[英]Multiple text data-bind using knockout
Hi i am trying to do a double data-bind on a option text. 嗨,我正在尝试对选项文本进行双重数据绑定。 Now i want to include 2 things within the select drop-down.
现在,我想在选择下拉列表中包括2件事。
I have tried this and it only brings back the last data-bind of the description. 我已经尝试过了,它只带回了描述的最后一个数据绑定。 is there a way to do 1 data-bind and include both values using knockout?
有没有一种方法可以进行1个数据绑定并使用剔除包括两个值?
<option value="" data-bind="text: Name, text: Description"></option>
You can do: 你可以做:
<option value="" data-bind="text: Name() + ' ' + Description()"></option>
Or better create a computed observable: 或者更好地创建一个可计算的可观察值:
this.ComputedName = ko.computed(function (){
return this.Name() + ' ' + this.Description();
});
and use it like this: 并像这样使用它:
<option value="" data-bind="text: ComputedName"></option>
You might also consider options binding instead. 您也可以考虑使用选项绑定 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.