灰烬多选选择不起作用

时间:2015-06-24 23:08:19

标签: ember.js

有谁知道为什么这个多选择没有显示两个预先选择的值?我预计这两个会被预选:'选项0'和'选项2'

http://jsfiddle.net/b75w560d/1/

我正在使用Ember 1.13

模板...                  

欢迎来到Ember.js

    {{outlet}}
  </script>

  <script type="text/x-handlebars" data-template-name="index">
         {{view "select"
            multiple=true 
            class="form-control input-sm" 
            content=pa.options 
            selection=pa.selectedList 
            optionValuePath="content.name" 
            optionLabelPath="content.name" 
            disabled=pa.isDisabled}}
  </script>

...的Javascript

App = Ember.Application.create();

App.Router.map(function () {
    // put your routes here
});

App.IndexController = Ember.ObjectController.extend({

    pa: function(){
        var optionsList = Ember.A();
        optionsList.pushObjects([
                    Ember.Object.create({name: 'Option 0'}),
                    Ember.Object.create({name: 'Option 1'}),
                    Ember.Object.create({name: 'Option 2'})
        ]);

        var selectedList = Ember.A();
        selectedList.pushObjects([
                    Ember.Object.create({name: 'Option 0'}),
                    Ember.Object.create({name: 'Option 2'})
        ]);

        return Ember.Object.create({
            isDisabled: false,
            options: optionsList,
            selectedList: selectedList
        });
    }.property()
});

1 个答案:

答案 0 :(得分:0)

Ember.Select不会对对象相等进行深度检查

含义var a = { foo:"bar"}var b {foo:"bar"}不相等

这是一个固定的小提琴http://jsfiddle.net/u6f0jdw5/

您会看到所选内容和选项都引用了现在可用的相同对象。

请参阅#5259#4331