我尝试了事件加载或准备运行搜索:函数(事件),当页面加载时无法生效,但是keyon可以执行搜索功能。我可以在外面调用搜索功能吗?可以调用页面加载吗?请帮忙,我是 jquery 的初学者。
directory.views.SearchPage = Backbone.View.extend({
templateLoader: directory.utils.templateLoader,
EmployeeListView: directory.views.EmployeeListView,
initialize: function() {
this.template = _.template(this.templateLoader.get('search-page'));
},
render: function(eventName) {
$(this.el).html(this.template(this.model.toJSON()));
this.listView = new directory.views.EmployeeListView({el: $('ul', this.el), model:this.model});
this.listView.render();
return this;
},
events: {
"keyup .search-key": "search",
"load .search-key": "search",
"ready .search-key": "search"
},
// Start the search function
search: function(event) {
var key = $('.search-key').val();
this.model.findByName(key);
}
});