2013-11-26 33 views
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/

+0

我试过使用模板,但它不工作。 – Ruchan

回答

0

您可以使用JavaScript字符串连接运算符+在你的绑定:

<option data-bind="text: Brand + '/' + Id + ' ' + Type"></option> 

演示JSFiddle

+0

谢谢,那工作。你也可以帮我使用jquery ui combobox吗? – Ruchan