简体   繁体   中英

Emberjs: Use a checkbox to display data

I have a data table with checkbox selection. If an item in the table is checked I want to display that data in another part of the page. Seems like it should be simple but I can't seem to figure it out. I made a js

JS Bin with data table example

Here is the controllers/route

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
});

I would like this to evolve to only allowing a single selection, but I'll address that once I can get the data to display.

You need to define the dependency ( property ) correctly. You have the computed property depending on the isSelected property on the controller itself. You need to make it dependent on the isSelected property on each member of productLinks , which you do with the @each syntax.

selectedProduct: function(){
    var selectedProd = this.get('productLinks').filterBy('isSelected', true);
    return selectedProd[0];
}.property('productLinks.@each.isSelected')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM