javascript - Parsing JSON file and storing into Backbone Collection, Error: __ is undefined -


i parsing json file getjson , storing results in array of models. after putting array of models in collection called data.

var dataarray = []; var url = 'file.json';  $.getjson(url, function (json) {     (var = 0; < json.var.length; i++) {        var varsamp = new datamodel();        (var j = 0; j < json.var[i].vartwo.length; j++) {             varsamp.set({'attr_1': json.var[i].attribute1});            varsamp.set({'attr_2': json.var[i].attribute2});            varsamp.set({'attr_3': json.var[i].vartwo[j].attribute3});             dataarray.push(varsamp);        }     }     });  var data = new datacollection(dataarray); console.log(data); 

when trying access collection view, receive error: typeerror: 'data' undefined.

here view:

var datacollectionview = backbone.view.extend({     el: '.content',      initialize:function(){         this.render();     },     render: function () {         var source = $('#view-temp').html();         var template = handlebars.compile(source);         var html = template(data.tojson());         this.$el.html(html);     }  }); 

the solution pass data view.

var view = new datacollectionview({collection: data}); 

followed by

initialize: function(options) {     this.render(options.collection); } 

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -