Reputation: 25
I have a local json file. I need to put these data in a Backbone.Collection
, then receive this collection in a Backbone.View
and render the data in a template. So I tried many ways but...
Model:
define([
'backbone',
], function(Backbone) {
var InfoModel = Backbone.Model.extend({
defaults: {
id : "",
name : "",
info : "",
img : "",
user : "",
userlvl : "",
mobile : "",
phone : "",
fax : "",
web : "",
email : "",
linkedin : "",
instagram : "",
twitter : "",
storeService : "",
departomanService: "",
shopBalence : "",
shopWithdrawal : "",
shopDeposit : ""
}
});
return InfoModel;
});
Collection:
define([
'backbone',
'core/application',
'components/persian_social_tinet/models/information',
], function(Backbone, Application,InfoModel) {
var InfoCollection = Backbone.Collection.extend({
model : new InfoModel(),
url : function(){
return 'json!data/' + Application.current_section + '/information.json';
},
parse: function(Response){
return Response;
}
});
return InfoCollection;
});
View:
define([
'backbone',
'components/persian_social_tinet/collections/information',
'text!components/persian_social_tinet/tpls/leftpanel-acc.html',
], function(Backbone, InfoColl, accTpl ) {
var accView = Backbone.View.extend({
className: 'account-leftPanel',
initialize: function() {
var infoColl = new InfoColl();
this.listenTo(InfoColl, "sync", this.render)
},
render: function() {
this.template = _.template(accTpl);
var item = { infoColl: this.infoColl.toJSON }
this.$el.html(this.template(item));
return this;
}
});
return accView;
});
I want to fetch the collection. However, the json data are not from a server but from the local filesystem. Please help me.
Upvotes: 1
Views: 137