我有一个带有复选框选择的数据表。如果选中表中的某个项目,我想在页面的另一部分显示该数据。看起来应该很简单,但我似乎无法弄清楚。我做了一个js
JS Bin with data table example
这是 Controller /路线
App.IndexController = Ember.Controller.extend({
productLinks: function(){
return this.get('content');
}.property('model', 'isSelected'),
selectedProduct: function(){
var selectedProd = this.get('productLinks').filterBy('isSelected', true);
return selectedProd[0];
}.property('isSelected'),
isSelected: null
});
我希望将其发展为仅允许单个选择,但一旦我能够显示数据,我就会解决这个问题。
最佳答案
您需要正确定义依赖项(属性
)。您拥有取决于 Controller 本身的 isSelected
属性的计算属性。您需要使其依赖于 productLinks
每个成员的 isSelected
属性,这是使用 @each
语法实现的。
selectedProduct: function(){
var selectedProd = this.get('productLinks').filterBy('isSelected', true);
return selectedProd[0];
}.property('productLinks.@each.isSelected')
关于javascript - Ember : Use a checkbox to display data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26069739/