के बजाय सभी संग्रह के लिए घटनाओं को सक्रिय करता है, यह पता नहीं लगा सकता कि क्या गलत है। जब मैं मॉडल शीर्षक पर क्लिक करता हूं, तो यह एक मॉडल को लाने के बजाय सभी मॉडलों को संग्रह में लाता है। अगर मैं इस घटना को लॉगव्यू से लॉग में ले जाता हूं तो देखें कि यह ठीक से काम करता है लेकिन मॉडल तक पहुंच नहीं है, ठीक है, मैं इंडेक्स या चींटी अन्य मॉडल आईडी का उपयोग करके यह मॉडल पा सकता हूं लेकिन यह नहीं लगता कि यह एक अच्छा तरीका है।बैकबोन क्लिक इवेंट मॉडल
var Log = Backbone.Model.extend({});
window.LogsList = Backbone.Collection.extend({
model:Log,
url:function (tag) {
this.url = '/logs/' + tag;
return this;
}
});
window.colList = new LogsList();
window.logView = Backbone.View.extend({
el:$('.accordion'),
template:_.template($('#log').html()),
initialize:function() {
this.model.bind('add', this.render, this);
},
events:{
"click .accordion-toggle" :"getLogBody"
},
render:function() {
return this.template(this.model.toJSON());
},
getLogBody:function() {
this.model.fetch();
}
});
window.LogsView = Backbone.View.extend({
el:$("#content"),
initialize:function (options) {
colList.bind('reset', this.addAll, this);
colList.url(options.data).fetch();
},
addOne:function (model) {
var view = new logView({model:model});
$("#accordion").append(view.render());
},
addAll:function() {
colList.each(this.addOne);
}
});
window.listView = new LogsView({data:"Visa_Cl"});
धन्यवाद, मुझे संदेह है कि मैंने इसके साथ गड़बड़ की है। – nateless
धन्यवाद आदमी! उत्कृष्ट संसाधन! –
धन्यवाद ... बस मुझे जो चाहिए था। –