我正在寻找一种方法来使用来自输入字段的值来过滤我的主干集合 - 为了实现这一点,我使用视图(“ KEYUP input.searchBookmark“: ”搜索“):backbone.js - 使用输入值筛选集合
window.BookmarksListView = Backbone.View.extend({
events: {
"keyup input.searchBookmark": "search"
},
el: $('#bookmarksList'),
initialize: function() {
this.model.bind("reset", this.render, this);
this.model.bind("add", function(bookmark) {
$('#bookmarksList').append(new BookmarksListItemView({model: bookmark}).render().el)
});
},
render: function(eventName) {
_.each(this.model.models, function(Bookmarks) {
$(this.el).append(new BookmarksListItemView({model: Bookmarks}).render().el);
}, this);
return this;
},
renderList: function(bookmarks) {
alert(bookmarks);
},
search: function(event) {
alert(event);
var query = $("#searchBookmark").val();
this.renderList(this.model.search(query));
}
});
的HTML:
<form class="pull-left" action="">
<input placeholder="Bookmarks..." type="text" class="searchBookmark" id="searchBookmark" value="">
</form>
输入元件不是在元件内 ”bookmarksList“。
我的问题是没有任何反应,如果我在输入中输入一些文本 - 可能是什么问题?