How to call a custom JSON request, then build a collection of models from that, using Backbone.js? -


i'm new backbone.js , have been trying understand 3 things: 1) how , call custom json request? 2) how translate json request model? 3) how create collection of models?

my json looks this:

{"flavor": "vanilla",   "message": "ok",   "count": 10,  "rows": [{"data":["this", "is", "123", "something"],            "moredata": "more stuff here",            "moreinfo": "more info here"},           {"data":["even", "more", "456", "something"],            "moredata": "even more stuff here",            "moreinfo": "even more info here"},           {"data":["it", "doesn't", "123", "end"],            "moredata": "more , more stuff here",            "moreinfo": "more , more info here"}] } 

i want have each "data" item. want list contain many items.

i have make custom json request (not via $.ajax or - in separate library has called via specific function, provides callback option) - make call in backbone.model or backbone.view?

basically json response format getting not within control, hence messy sample above. i'd format of json nicer attributes bonus. hoping in item model.

how can translate request model? if have modify attributes?

how can create collection of models? far have

    var itemlist = backbone.model.extend({      })      var itemlists = backbone.collection.extend({        model: itemlist,      });      var itemview = backbone.view.extend({        el: $("#dashboard"),        template: _.template($("#item-template")),        initialize: function(){         this.render();       },        render: function(){         var item = new item();         var content = this.template(item);         $(this.el).html(content);       }     });  

please help, backbone.js experts. should relatively straightforward question experienced!

var itemlist = backbone.model.extend({     parse: function(response) {         // response = {"data":["this", "is", "123", "something"],         // "moredata": "more stuff here",         // "moreinfo": "more info here"}         // can make additional changes here         return response;     } });  var itemlists = backbone.collection.extend({    model: itemlist,   parse: function(response) {       return response.rows;   }  }); 

is thinking? takes rows , makes each 1 itemlist. can other manipulation within parse, if needed. can set url , use fetch.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -