嗨,目前我用ember视图动态创建了一些按钮:
{{#each item in content._data.cpu_choices}}
{{#view App.CPUSelButView id=item value=item name="cpu_button" disabled=cpu_Not_Allow}}{{item}}x{{/view}}
{{/each
{{#each item in content._data.cpu_choices}}
{{#view App.CPUSelButView id=item value=item name="cpu_button" disabled=cpu_Not_Allow}}{{item}}x{{/view}}
{{/each
我的观点是
}
// View used for CPU selection buttons
App.CPUSelButView = Ember.View.extend({
tagName: 'button',
// class names, :emberbutton for CSS style
classNameBindings: [':emberbutton', ':btn', ':btn-primary', ':btn-xs'],
// html attributes, custom (e.g. name, value) should be defined here
attributeBindings: ['disabled', 'name', 'value'],
// on click
click: function () {
// for this controller, trigger the CPU_selection and send the value
this.get('controller').send('cpu_selection', this.get('value'));
}
我现在想要的是将id从item(动态)更改为some_stirng_item,使用前缀到当前id实际上有一种方法可以做到这一点。
我需要id来按ID搜索元素。
答案 0 :(得分:1)
我通过将此添加到我的视图中解决了我的问题:
// Set this view's id
init: function() {
this.set('elementId', "cpu_" + this.get('value'));
return this._super();
},
// Set this view's id
init: function() {
this.set('elementId', "cpu_" + this.get('value'));
return this._super();
},