有人可以幫助我嗎?Knockoutjs Array Filter
如何獲得多選列表以擁有獨特的國家?另外,如何根據多選中選擇的項目篩選記錄?
下面是的jsfiddle http://jsfiddle.net/B2xcv/代碼
請幫助。
謝謝。
HTML
<div class='liveExample'>
<p style="color:red">How do I make this list unique?</p>
<p>
<select data-bind="options: people,optionsText: 'country', selectedOptions: selectedCountries" size="5" multiple="true" style="width:150px"></select>
</p>
<p style="color:red">And how do I filter the records below based on the selected items above? (multiple select)</p>
<table style="width:300px">
<thead>
<th>Name</th>
<th>Location</th>
</thead>
<tbody data-bind="foreach: people">
<tr>
<td>
<span data-bind="text: name"> </span>
</td>
<td>
<span data-bind="text: country"> </span>
</td>
</tr>
</tbody>
</table>
</div>
KnockoutJS
// Define a "Person" class that tracks its own name and children, and has a method to add a new child
var Person = function(name, country) {
this.name = name;
this.country = country;
}
// The view model is an abstract description of the state of the UI, but without any knowledge of the UI technology (HTML)
var viewModel = {
people: [
new Person("Annabelle", "UK"),
new Person("Bertie", "UK"),
new Person("Bertie", "USA"),
new Person("Ali", "Bangladesh"),
new Person("Patel", "India"),
new Person("Sweatha", "India"),
new Person("Minto", "India"),
],
selectedCountries: ko.observableArray()
};
ko.applyBindings(viewModel);
非常感謝您的快速回復。 :) – Huzzi
這個答案與我正在尋找的東西沒有直接關係,但是我僅僅爲答案的純粹質量而努力。做得好! –
@DavidMontgomery I:P –