4
我怎么能访问正在ember.js视图插入,从视图本身的DOM元素的属性。这是一个简短的例子。比方说,我有以下cat.handlebars
模板:访问属性
{{#collection contentBinding="App.catsController"}}
<div class="cat" {{bindAttr id="view.content.id"}}></div>
{{/collection}}
这是在该视图中使用:
App.CatView = Ember.View.extend({
templateName: 'cat',
catsBinding: 'App.catsController',
didInsertElement:() ->
#need to get the id of each DIV that is being inserted to add some JavaScript for it
console.log 'context it ', this.$()
})
this.$()
返回一个嵌套很深的对象,我无法找到我在它的DIV的迹象。此外,当我是didInsertElement
函数内部view.content.id
没有定义。
要重申我的问题,当我是一个观点,我怎么可以添加相关的一些正在通过视图插入的DOM元素的一些JavaScript代码里面。