2012-09-13 87 views
0

我嘗試瞭解模板綁定如何與WinJS一起使用。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}只是一些將被模板引擎解析和更換

感謝

回答

2

沒有,是在WinJS沒有這樣的語法結合。

但是,您可以改寫它。

<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創建的。您可以替換或修改此功能並添加您自己的模板引擎。

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; 

希望這有助於。