Backbone.js: complex views combining multiple models

后端 未结 2 409
梦谈多话
梦谈多话 2020-12-23 11:39

So far all tests and tutorials i\'ve been trying, to get the structure in my head, show me that a view is bound to 1 model.

lets say i have a small app to store and

2条回答
  •  失恋的感觉
    2020-12-23 12:41

    You can also consider merging both models, if you are sure they dont use the same parameters.

    var modelA = new myModel({ color: "blue" });
    var modelB = new otherModel({ age: 35 });
    
    var superModel = new Backbone.Model();
    superModel.set(modelA);
    superModel.set(modelB);
    
    console.log("color:", superModel.get("color"));
    console.log("age:", superModel.get("age"));
    

    take a look at Backbone.Model.extend() as well

提交回复
热议问题