0

我试图了解模板绑定如何与 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>

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

谢谢

4

2 回答 2

2

No, there is no such syntax in WinJS Binding.

You can write this instead, however.

<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>

Otherwise, bindings are actually created by WinJS.Binding.processAll. You can replace or monkey-patch this function and add your own template engine.

于 2012-09-13T11:56:52.793 回答
0

你可以做类似的事情

<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;

希望这可以帮助。

于 2015-07-25T15:19:34.517 回答