मेरे मॉडल के विचारों के लिए मेरे पास 2 अलग-अलग टेम्पलेट हैं। प्रत्येक बार मॉडल को डेटाबेस से लाया जाता है, बैकएंड से प्राप्त पहले 3 मॉडल (# 1, 2, 3) में पहले टेम्पलेट का उपयोग करके बनाया गया दृश्य होगा, अगले 4 मॉडल (# 4, 5, 6, 7) दूसरे टेम्पलेट का उपयोग करेंगे, अगले 3 मॉडल (# 8, 9, 10) पहले टेम्पलेट का उपयोग करेंगे और इसी तरह।backbone.js में 2 अलग-अलग टेम्पलेट्स के बीच वैकल्पिक
समस्या: मैं backbone.js का उपयोग करके इस वैकल्पिक टेम्पलेट को कैसे पेश करूं?
जे एस कोड
// Views
PhotoListView = Backbone.View.extend({
el: '#photo_list',
render: function() {
$(this.el).html('');
_.each(this.model.models, function(photo) {
$(this.el).append(new PhotoListItemView({ model: photo }).render().el);
}, this);
return this;
}
});
PhotoListItemView = Backbone.View.extend({
tagNAme: 'div',
className: 'photo_box',
template: _.template($('#tpl_PhotoListView').html()),
initialize: function() {
this.model.bind('destroy', this.close, this);
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
close: function() {
this.unbind();
this.remove();
}
});
महाकाव्य जवाब महाकाव्य है ... आप –
पूरी तरह से महाकाव्य धन्यवाद। धन्यवाद धन्यवाद! – Nyxynyx
प्रश्न: प्रत्येक तत्व के लिए प्रस्तुत किया जाएगा और दृश्य ताज़ा किया जाएगा। क्या हम इसे अनुकूलित कर सकते हैं? –