Friday, 15 June 2012

javascript - Backbone rendering collection in other collection element -


I have a structure that I need to render. Its linear types are: [{name: [{name: "D17043"}, {name: "D91832"}, {name: "D32435"}}, buildings: [{name: "B14745", District: "D 17043 ", Address:" First Phase "}, {Name:" B14746 ", District:" D9 1832 ", Address:" First Phase "}, {Name:" B14747 ", District:" D 17043 " Address: "First St"}]}

It is easy to look a little better In the districts they have attached buildings. Probably, the structure can be nested, but I thought it would create additional trouble, and, because this "tree" is not structured, I have made simple objects. The question is how can it be displayed properly with the spinal cord? It looks like something like this (some details are left behind the scenes):

  App Colections. Distills = Backbone compilation. Extension ({Model: App.Models.District}); Var district = edit new app. Selection .Digital (Data Distilled); See Var district = new app View. District ({Collection: Districts Collection});  

Then in the district archive scene, we create a loop that creates a single district scene:

  View the district = new app. View. District ({model: district});   

and within the same district call the second collection in the view i render method:

  App.Views.District = Backbone.View.extend ({tagname: 'div', classname: 'district listname', render: function () {this. $ El.html (this.model.get ('name') ); Select Var buildings = new app.collections.Imons (All data.building); Selecting buildings.Composition (task (object) (if (item.get ('district') == this.model.get (' Name ')) {var buildingview = New App.Views.Building ({Model: items}), this. $ El.append (buildingView.render (). El);}}, this); }};  

This thing works but it's not a bit scary? Maybe it's a fair way to do this? Especially if I have a building inside other buildings, thanks. < / P>


No comments:

Post a Comment