我有这样的组件,并希望在其上设置一些属性:
OlapApp.ItemRowsComponent = Ember.Component.extend({
tagName: 'li',
classNameBindings: ['currentItem.isMeasure:d_measure:d_dimension'],
didInsertElement: function() {
this.$().draggable({
});
},
actions: {
removeItem: function(item) {
item.deleteRecord();
item.save();
},
didClick: function(item) {
if (item.get('isMeasure')) {
item.deleteRecord();
item.save();
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
我把这个组件称为:
{{#each item in getRowItem}}
{{item-rows currentItem=item}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
item有一个id属性item.id现在我想将这个id设置为component的data-id来创建一个这样的元素:
<li data-id='id of item'>Some text</li>
Run Code Online (Sandbox Code Playgroud)
你的方法真的有效吗?我怀疑它不应该那样工作,而应该是:
OlapApp.ItemRowsComponent = Ember.Component.extend({
attributeBindings:["data-id"],
"data-id" : Ember.computed.oneWay("currentItem.id")
// and the rest of your code ...
});
Run Code Online (Sandbox Code Playgroud)
还有一点需要注意:查看我的博客文章,了解如何正确执行jquery逻辑:http://mavilein.github.io/javascript/2013/08/01/Ember-JS-After-Render-Event/
经过搜索并尝试某种方法后我发现了这一点。我用它来解决我的问题:
attributeBindings:['getId:data-id'],
getId:function(){return this.get('currentItem.id')}.property(),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5834 次 |
| 最近记录: |