灰烬选择选择绑定可观察不起作用,

时间:2013-12-23 14:42:04

标签: javascript jquery ember.js

App.Select2Users = Ember.Select.extend({
    attributeBindings: ['class'],
    selectedValueBinding: this.get('selectionBinding'),
    didInsertElement: function () {
        Ember.run.scheduleOnce("afterRender", this, "processChildElements");
    },
    value: Ember.computed(function(key, value){
        alert('haah');
    }),
    processChildElements: function () {
        var self = this;
        $(this.$()).select2({}).on('change', function (e) {
            var context = self.get('context');
            var currentValues = self.get(self.selectionBinding._from);
            e.val.forEach(function (val) {
                if (!_.contains(currentValues, val))
                    currentValues.push(val);
            });
            self.set(self.selectionBinding._from, currentValues);
        })
    },
    propertyWillChange: function () { alert('se'); },
    willDestroyElement: function () {
        $(this.$()).select2('destroy');
    }
});

以上是我的选择视图。我在选择的倍数上使用select2.Below是我的控制器,

App.NewController = Ember.Controller.extend({
    selectedUsers:[],
    users: [{ userId: "Logan", department: "Frontline" }, { userId: "Logan2", department: "Frontline2" }],
    users: null,

    userSelected: function () {
        alert('user selected');
    }.observes('selectedUsers.@each'),
});

每次从选择列表中选择项目时,插件都会工作并更新selectedUsers。但是函数userSelected不会被调用。据我所知,每当一个可观察的财产被修改时,偶数就会被激活。我是对的吗?

0 个答案:

没有答案