私は検索フォームを持っています:
<form class="navbar-search pull-right" data-bind="submit: findBook">
<input type="text" class="search-query" placeholder="Search" id="search-input">
<i class="icon-search"></i>
<input type="submit" value="Submit">
</form>
私はここに本をリストしています:
<ul id="container" class="list" data-bind="foreach: books">
<li>
<div>
<table>
<tr>
<td class="center">
<a data-bind="attr:{href: url}">
<img width="150" class="img-polaroid shadow" data-bind="attr:{src: image}">
</a>
</td>
</tr>
<tr>
<td class="center">
<h6 data-bind="text: name"></h6>
</td>
</tr>
</table>
</div>
</li>
</ul>
そしてfindBook
私のViewModelのメソッド:
self.books = ko.computed(function() {
return ko.utils.arrayFilter(library, function(book) {
return self.selectedCategory() == null ||
book.category === self.selectedCategory();
})
});
self.findBook = function() {
self.books = ko.computed(function() {
return ko.utils.arrayFilter(library, function(book) {
return book.name.match(new RegExp($('#search-input').val(), 'i'));
});
});
};
}
私は何が欠けていますか?