2

I cannot fire observes function when was created object in Controller Array

My code:

Model

App.Meeting = Em.Object.extend({
    id: null,
    name: null,
    type: null,
    proposes: null
 });
App.Meeting.reopen({
    proposedChanged: function() {
       //some do
    }.observes('proposes')
});

Controller

App.meetingsController = Ember.ArrayController.create({
    content: [],
    loadList: function(){
        var me = this;
        $.getJSON(url,function(data){

            if(data.status == 0){
                $(data.meetings).each(function(index,value){
                    var m = App.Meeting.create(value)
                    me.pushObject(m);    
                });

            }else{
                alert('Error loading content');
            }               
        });
    },

});

App.meetingsController.loadList();

When i run application Controller has get JSON data and created App.Meeting with that data, but observer not fire

4

2 回答 2

2

当我创建一个 jsbin 来与@Darshan Sawardekar 一起玩时,它是正确的,所以现在你必须回答才能玩:)

重要代码:

App.meetingsController = Ember.ArrayController.create({
  content: [],
  loadList: function(){
    var me = this;
    $.getJSON(url, function(data){
      if(data.status == 0){
        $(data.meetings).each(function(index, value){
          var m = App.Meeting.create();
          m.set('id', value.id);
          m.set('name', value.name);
          m.set('type', value.type);
          m.set('proposes', value.proposes);

          me.pushObject(m);
        });
      } else {
         alert('Error loading content');
      }               
    });
  }
});

希望能帮助到你。

编辑

有关显示该概念的工作jsbin ,请参见此处。

于 2013-07-18T11:15:42.193 回答
1

我认为当你这样做时,观察者会开火meeting.set('proposes', 'value')。他们不会在create通话中开火。您可以修改您的创建以修饰建议。这可能有效,

var m = App.Meeting.create(value);
m.set('proposes', value.proposes);
于 2013-07-18T10:57:52.530 回答