我正在通过操作修改一个属性,但 Ember 不会更新渲染的模板。
我的 Controller :
selected_rows_id: [],
actions: {
selectRow(rowId) {
let selected_rows = this.get('selected_rows_id');
if (selected_rows.indexOf(rowId) === -1) {
selected_rows.push(rowId);
// selected_rows.pushObject(rowId); does not work either
}
this.set('selected_rows_id', selected_rows);
},
}
在我的模板中,我使用 {{selected_rows_id}}
显示我的元素
我创建了一个 twiddle展示我做了什么
最佳答案
使用pushObject
而不是push
:
actions: {
selectRow(rowId) {
let selected_rows = this.get('selected_rows_id');
selected_rows.pushObject(rowId);
},
}
关于javascript - 修改 Controller 属性时,Ember 不更新模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41126748/