这是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>
我如何连接 {Brand}/{Id} + {type} .
您可以+
在绑定中使用JavaScript字符串串联运算符:
<option data-bind="text: Brand + '/' + Id + ' ' + Type"></option>
演示JSFiddle。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句