बैकबोन के लिए नया, कृपया मेरा सुंदर बैकबोन जावास्क्रिप्ट कोड न रखें।बैकबोन जेएस ऑटो रीफ्रेश/सर्वर से पुनः लोड करें और संग्रह के साथ अपडेट अपडेट करें
यह मेरा कोड
var Schedule = Backbone.Model.extend({
initialize: function() {
console.log("initializing model");
}
});
var ScheduleCollection = Backbone.Collection.extend({
model: Schedule,
url: "<%=students_swimming_classschedules_path%>",
parse: function (resp) {
return resp;
},
});
var Schedules = Backbone.View.extend({
initialize: function() {
console.log("initializing view");
collection.on('add', this.render, this);
this.render();
},
render: function() {
for (var i = 0; i < collection.length; i++) {
s += "<tr><td>" + collection.models[i].get('account') + "</td><td>" + collection.models[i].get('status') + "</td></tr>";
}
this.$el.html(s);
},
})
var schedules = new Schedules({
el: $("#students")
});
window.setInterval(function() {
collection.fetch();
}, 2000);
इस कोड काम करता है। और मैं सभी छात्रों को $ ('# छात्र') कंटेनर में लोड कर सकता हूं।
लेकिन मैं सर्वर से संग्रह को फिर से लोड करना चाहता हूं और प्रत्येक कुछ सेकंड में दृश्य को पुनः लोड करना चाहता हूं। किसी भी सहायता की सराहना की जाएगी।
मैंने अपना कोड अपडेट किया है। 'Collection.on जोड़ें ('जोड़ें', this.render, यह); 'और' window.setInterval (फ़ंक्शन() { collection.fetch(); }, 2000); और इन पूर्व संग्रह को हटा दिया गया।()। लेकिन $ ("# छात्र") कैसे लोड नहीं हो रहे हैं? – wwli
और मैं इस संग्रह में सबकुछ फिर से लोड करना चाहता हूं न कि संग्रह – wwli
संग्रह में नए आइटम जोड़ें, मुझे लगता है कि मैंने इसे समझ लिया है। मैंने 'collection.on ('add', this.render, this) बदल दिया; 'संग्रह' के साथ ('सिंक', यह। प्रस्तुत करें, यह); ' – wwli