मेरे पास एक ऐसा दृश्य है जो एक चयनसूची बनाता है और पॉप्युलेट करता है। मैं परिवर्तन ईवेंट पर एक घटना बाध्य करने के लिए (उपयोगकर्ता एक अलग विकल्प का चयन करता है चाहता हूँबैकबोन व्यू में एल पर एक घटना को ट्रिगर करना
यह बस इस के करीब कुछ आउटपुट:।
<select>
<option value="id">ID Name</option
</select>
दृश्य:
App.Views.SessionList = Backbone.View.extend({
tagName: 'select',
id: 'sessionList',
events: {
'change': 'selectionChanged'
},
initialize: function() {
// Load Collection
_.bindAll(this, 'selectionChanged');
this.template = _.template($('#optionsTemplate').html());
this.Sessiontemplate = _.template($('#session_template').html());
this.SelectedSessiontemplate = _.template($('#selected_session_template').html());
// Create Collection
this.SessionList = new App.Collections.SessionList();
// Set Bindings
this.SessionList.bind('add', this.addSession, this);
this.SessionList.bind('reset', this.addSessions, this);
this.render();
this.SessionList.fetch();
},
render: function() {
return this;
},
addSession: function (item, num) {
if (num === 0) {
$(this.el).append(this.SelectedSessiontemplate(item.toJSON()));
console.log("Selected");
}
else {
$(this.el).append(this.Sessiontemplate(item.toJSON()));
}
},
addSessions: function() {
var self = this;
// Add all Rows
for (var i = 0; i < self.SessionList.models.length; i++) {
this.addSession(self.SessionList.models[i], i);
}
},
selectionChanged: function (e) {
var field = $(e.currentTarget);
var value = $("option:selected", field).val();
}
});
सत्र टेम्पलेट बस बस है:
<option value="{{Id}}">{{Name}}</option>
घटना कभी ट्रिगर नहीं होती है, और ऐसा लगता है कि यह सही ढंग से बाध्य नहीं हो रहा है। मैं इसे चुनिंदा सूची में बदलने के लिए ट्रिगर करना चाहता हूं।
मैंने मूल रूप से सोचा कि मुझे एक समस्या हो सकती है: backbone.js events and el, हालांकि यह इस मामले में काम नहीं करता है।
मूर्खतापूर्ण, लेकिन क्रोम पृष्ठ को कैश कर रहा था और कई प्रयासों के बाद अपडेट भी नहीं दिखाए जा रहे थे। लेकिन, मैंने आपके बेवकूफ का उपयोग किया, जिसने मुझे कुछ चीजों को बनाने और ठीक करने की अनुमति दी। धन्यवाद! – Hyper