javascript - How to create a Backbone Collection with data that is not flat -
I'm not sure how to create a backbone collection using the following data, and how surprising it should be.
In JSON the Here are some examples of data and code: <% - element.title% & gt;, <% - element.color% & gt;, & lt;% _ Each (element.type, function (ele, i) {%> & lt;% - ele.is standard =>, <% - ele.size% & gt;, & lt;%});%> & lt;% - element.prince%> It seems that the eusted nested model is given here For more information checkout, here is a prototype to capture the idea 1) Create models and collections for items 2) Create a parent model, resembles page in your case: If you have an array in JSON resp, you can also create PageCollection as well. item property makes sense for me to use as a collection because it already has an array but what other information for the collection is available Is there a good way, or in case of maintaining it, it needs to be referenced in a scene? How should I manage the following data format for archiving?
{"page": 1, "total": 1000, "item": [{"title": "item 1 "title", "color": "green", "type": [{"standard": "yes", "size": "big"}, {"isStandard", "size": "medium" } "," "{Title}", "title": "title of item 2", "color": "blue", "type": [{"IsStandard": "", "size": " "" "," Color ":" red "," type "," type "," "" 9.9 ":" value ":" value ":" {{"isstandard": "no", "size": "small"}, {"isstandard": "yes", "size": "big"}] }], "Date": "Wednesday 08 October 2014 21:04 : 05 GMT-0500 (CDT) "}
var SomeModel = Backbone.Model.extend ({}); Var SomeCollection = Backbone.Collection.extend ({models: SomeModel, url: 'https://api.mongolab.com/api/1/databases/backbonecollectiontest/collections/backbonecollection?apiKey=qcVNgNb-s1X4WJkLeRDfykxqtMG-ezkC', parsing: Function (response) {// Only item data is returning. But in response this data will disappear / that item is not included in the return response of items [0] .aams;}}); Var SomeView = Backbone.View.extend ({L: '.js- container' Start: function () {this.collection = new SomeCollection (); this.collection.fetch (); this.listenTo (this.collection, 'Sync', this.render);}, Template: _template ($ ('# -teamplate'). Html ()), render: function () {this. $ El.html (this.template ({archive : This.collection.toJSON ()})))}}}); Var someView = new view ();
and div
Var item = backbone.model. Extension ({default: {"title": "no-title", "color": "no", "type": [], "value": "0"}}); Var image resolution = backbone.collection.andend ({model: items});
var PageModel = Backbone.Model.extend ({default: {page: 0, date: 'now', total: 0, item: []}, start: function () {var item = this.get ('item'); this.set ('item', new item compilation (item) );}});
Comments
Post a Comment