我试图在我的backbone.js 视图中绑定两个函数,但不知道为什么它不起作用..
任何人都可以建议?
define([
'jquery',
'underscore',
'backbone',
'libs/jquery_ui_dependency',
'vehicle/js/collections/MakeSet',
'vehicle/js/collections/ModelSet',
'vehicle/js/collections/TrimSet',
'vehicle/js/collections/YearSet',
'vehicle/js/views/Paginator'
], function($, _, Backbone, JQueryUi, MakeSet, ModelSet, TrimSet, YearSet, Paginator){
'use strict';
var BrowseVehicleView = Backbone.View.extend({
el: $('#vehicle-browse-form'),
initialize: function(){
JQueryUi.init();
_.bindAll(this, 'render', 'onMakeChange');
//define array of elements to be used in DOM manipulations
this.elements = {
"make" : $('#id_make', this.el),
"model" : $('#id_model', this.el),
"trim" : $('#id_trim', this.el),
"year_from" : $('#id_year_from', this.el),
"year_to" : $('#id_year_to', this.el),
"price_from" : $('#id_price_from', this.el),
"price_to" : $('#id_price_to', this.el)
}
},
events: {
"change #id_make" : "onMakeChange",
"change #id_model" : "onModelChange",
"change #id_trim" : "onTrimChange"
},
render: function(){
Paginator.filter({
model__make: this.elements.make.val(),
model__model: this.elements.model.val(),
model__trim: this.elements.trim.val()
});
},
onMakeChange: function(event) {
this.resetElement([
this.elements.model,
this.elements.trim,
this.elements.year_from,
this.elements.year_to
]);
// load models
this.RenderCollection(ModelSet, {make: this.elements.make.val()}, [this.elements.model]);
},
在这里想要实现的是,每次调用 onMakeChange 时,它都应该调用渲染函数来渲染 Paginator.filter()