我想知道在调用视图时是否有一种方法可以在模板中绑定数据属性.
例如(这不起作用):
{{ view App.SomeView data-dateBinding="currentDate" }}
Run Code Online (Sandbox Code Playgroud)
我最终这样做了:
<a {{bindAttr data-date="currentDate"}}></a>
Run Code Online (Sandbox Code Playgroud)
调用视图时必须有办法吗?
cap*_*ete 13
更多关于@ kurt-ruppel的优秀答案.
:用于描述属性绑定属性的示例,完全从视图中完成.
App.SomeView = Ember.View.extend({
attributeBindings: ["date:data-date"],
date: function() { return '1642-12-06' }
.... rest of view
})
Run Code Online (Sandbox Code Playgroud)
清洁模板.
{{view App.SomeView}}
Run Code Online (Sandbox Code Playgroud)
Bra*_*est 10
您必须在App.SomeView中定义要放在HTML中的属性.
App.SomeView = Ember.View.extend({
attributeBindings: ["data-date"]
.... rest of view
})
Run Code Online (Sandbox Code Playgroud)
现在data-dateBinding应该工作:
{{view App.SomeView data-dateBinding="currentDate" }}
Run Code Online (Sandbox Code Playgroud)