0
Concat的淘汰賽值這是JavaScript如何在組合框中
var ViewModel = function() {
var self = this;
self.vehicles = ko.observableArray([{
Id: 1,
Brand: "Volkswagen",
Type: "Golf"
}, {
Id: 2,
Brand: "Volkswagen",
Type: "Sharan"
}, {
Id: 3,
Brand: "BMW",
Type: "118i"
}, {
Id: 2,
Brand: "BMW",
Type: "525D"
}]);
self.brands = ko.computed(function(){
var list = ko.utils.arrayMap(self.vehicles(), function(item){
return item.Brand;
});
return ko.utils.arrayGetDistinctValues(list);
});
};
ko.applyBindings(new ViewModel());
$("select").multiselect();
,這是HTML與淘汰賽
<select data-bind="foreach: brands" multiple="multiple" >
<optgroup data-bind="attr: {label: $data}, foreach: $parent.vehicles">
<!-- ko if: Brand == $parent -->
<option data-bind="text: Type"></option>
<!-- /ko -->
</optgroup>
</select>
我如何Concat的的{Brand}/{Id} + {type} .
http://jsfiddle.net/ruchan/ARF29/2/
我試過使用模板,但它不工作。 – Ruchan