但我尝试这不起作用,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();
//var thiskey = ' ';
//this.model.findByName();
//alert("HELLO WORLD!1");
return this;
},
events: {
"keyup .search-key": "search"
},
// Start the search function
search: function(event) {
var key = $('.search-key').val();
this.model.findByName(key);
}
});
我尝试学习 Jquery,但我在这里遇到了一些问题......请在下面提供一些帮助:
我在下面有一个 Backbone 的 SearchView,我希望页面加载运行这个 SearchView,我编写了一个事件页面“准备好”和“加载”,但是页面加载时没有触发......
我有一个问题如何使页面加载运行此功能?或者如何在外部函数中调用这个 SearchView 主干?
SearchView = Backbone.View.extend({
initialize: function(){
this.render();
},
render: function(){
var template = _.template( $("#search_template").html(), {} );
this.$el.html( template );
},
events: {
"click input[type=button]": "doSearch",
"keyup": "doSearch",
"load": "doSearch",
"ready": "doSearch"
},
doSearch: function( event ){
// Button clicked, you can access the element that was clicked with event.currentTarget
alert( "Search for " + $("#search_input").val() );
}
});
var search_view = new SearchView({ el: $("#search_container") });