1
這裏有一個簡單的例子如何在Ember中輸出字符串,同時仍然通過車把解釋?
MyApp.ApplicationController = Ember.Controller.extend({
content: "some @user",
parsedContent: function() {
return this.get("content").replace("@user", "<a {{action gotoUser 'user'}}>user</a>");
}.property("content")
});
將輸出
some @user
some <a {{action gotoUser 'user'}}>user</a>
,而不是解釋的內容作爲把手模板。我想我需要編譯這個手冊,但我不知道如何傳遞正確的上下文。
雖然它似乎工作,它不會數據綁定。嘗試在JSFiddle中執行'MyApp.get(「router.applicationController」).set(「content」,「whatever」)',它不會重新呈現模板。 –
再一次,一個表現的事情,快速解決方法是將把手改爲「{{#with content}} {{view MyApp.LinkedUsersView contentBinding =」this「}} {{with}}' –
或者你也可以創建一個觀察者,當內容改變時重新渲染視圖。 http://jsfiddle.net/bradleypriest/6p6XJ/253/ –