我想问一下directory.views.SearchPage是什么?我能按上述方式调用此功能吗?可以调用页面加载吗?
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"
},
// Start the search function
search: function(event) {
var key = $('.search-key').val();
this.model.findByName(key);
}
});
答案 0 :(得分:2)
根据我的理解,您希望在页面加载时初始化,渲染然后调用主视图类上的“共享”功能。由于jQuery可用,我只想简单地使用:
var searchPage = new directory.views.SearchPage();
$(document).ready(function(e) {
searchPage.render();
searchPage.search(e);
});
但请注意: