誰かがこれで私を助けてくれますか?
複数選択リストに一意の国を含めるにはどうすればよいですか? また、複数選択で選択されたアイテムに基づいてレコードをフィルタリングするにはどうすればよいですか?
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>
ノックアウトJS
// 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);