【问题标题】:WinJS inline Binding SyntaxWinJS 内联绑定语法
【发布时间】:2012-09-13 08:31:08
【问题描述】:

我试图了解模板绑定如何与 WinJS 一起工作。

我发现你必须在数据属性上指定绑定:

<div data-wind-bind="innerText:myProperty"></div>

我想我还看到了可以定义多个属性的东西...

<div data-wind-bind="style.color: fontcolor; innerText: timestamp"></div>

是否还有与其他模板引擎类似的语法,我可以指定它的内联方式(只是其他模板引擎的一个示例)

<div>This is my property {{property1}} and it was created {{created_at}}</div>

现在重要的是它的 &lt;% property %&gt;#{property} 只是将被模板引擎解析和替换的东西

谢谢

【问题讨论】:

    标签: javascript windows-8 microsoft-metro winjs


    【解决方案1】:

    不,WinJS Binding 中没有这样的语法。

    不过,您可以改为这样写。

    <div>This is my property <span data-win-bind="innerText:property1"></span> and it was created <span data-win-bind="innerText:created_at"></span></div>
    

    否则,绑定实际上是由WinJS.Binding.processAll 创建的。您可以替换或猴子补丁此功能并添加您自己的模板引擎。

    【讨论】:

      【解决方案2】:

      你可以这样做

      <div>This is my property <span data-win-bind="innerText: property1">property1</span> and it was created <span data-win-bind="innerText: created_at">created_at</span></div>
      

      或者,当然,您也可以使用 javascript 来实现相同的结果,方法是这样做:

      // somefile.html
      <div id="someID">This is my property {{property1}} and it was created {{created_at}}</div>
      
      // somefile.js
      var property1 = "some text";
      var created_at = "some text";
      var div = document.getElementById("someID");
      div.innerText = "This is my property " + property1 + " and it was created " + created_at;
      

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-21
        • 1970-01-01
        • 1970-01-01
        • 2013-04-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多