[英]KnockOut Data-Bind Visible Causes Bad HTML
I use bootstrap with KnockOut. 我在KnockOut中使用引导程序。 When I use classical way, it looks like below.
当我使用经典方式时,如下所示。
<div class="col-md-6">
<label for="element2" class="field-title">Kazandıran Şube</label>
<select class="form-control select2" tabindex="15" data-bind="options: BranchList, optionsText: 'Label', optionsValue: 'StringValue', value: CustomerDataTransformObject.Customer.ConsolidationPlace, newChosen: {}"></select>
</div>
But when I use visible binding, it crashes like this. 但是,当我使用可见绑定时,它像这样崩溃。
<div class="col-md-6" data-bind="visible: CustomerDataTransformObject.Customer.Type() == 'Tüzel/Kurumsal'">
<label for="element2" class="field-title">Tüzel/Kurumsal Tip</label>
<select class="form-control select2" tabindex="10" data-bind="options: CommercialTypeList, optionsText: 'Label', optionsValue: 'StringValue', value: CustomerDataTransformObject.Customer.Commercial.Type, newChosen: {}"></select>
</div>
How can I solve this problem? 我怎么解决这个问题?
The main problem is totally about data-bind: visible. 主要问题完全与数据绑定有关:可见。 Because when you use visible binding for div, it can't calculate the real size of it.
因为当您对div使用可见绑定时,它无法计算其实际大小。 So I had to fix the size of select component.
所以我不得不固定选择组件的大小。 The unique solution is adding
$(element).css("width", "100%");
唯一的解决方案是添加
$(element).css("width", "100%");
to newChosen binding definition. 到newChosen绑定定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.