0

I'm having this

ServerInfoModel = Backbone.RelationalModel.extend({     
    relations: [
        {
            type: Backbone.HasMany,
            key: 'data',
            relatedModel: 'Data',
            collectionType: 'DataCollection',
            reverseRelation: {
                key: 'id',
                includeInJSON: 'id'
            }
        }
    ]
})
Data = Backbone.RelationalModel.extend({
});

DataCollection = Backbone.Collection.extend({
    model: Data
});

Now I have a view Associated with ServerInfoModel. If I change a value from model Data within that collection, "change" is not triggered on ServerInfoModel, is triggered only on DataCollection;

How can I pass the "change" event to ServerInfoModel from DataCollection ?

4

1 回答 1

1

我发现了怎么做,只听“数据”变化并进一步触发“变化”

ServerInfoModel = Backbone.BaseRelationalModel.extend({
url: function () {
    return "/examples/serverInfo.json"
},
setup: function () {
    var self= this;
    this.get('data').on('change', function () {
        self.trigger("change");
    });
},

relations: [
    {
        type: Backbone.HasMany,
        key: 'data',
        relatedModel: 'Data',
        collectionType: 'DataCollection',
        reverseRelation: {
            key: 'id',
            includeInJSON: 'id'
        }
    }
]
});

Data = Backbone.BaseRelationalModel.extend({ 
});

DataCollection = Backbone.Collection.extend({
  model: Data
});
于 2013-10-24T16:02:59.320 回答