每当我输入optionsCaption属性时,数据都不会绑定,否则它会很好地工作,并根据下拉列表的选定值绑定其他三个值。 ExpenseIO是模型,PlantList是一个可观察的数组。 PlantDescription,PlantCode,CompanyCode和CompanyDescription已在MasterModel.js下定义。请帮忙。
<div>
<span>Plant</span>
<span>
<select data-bind="options:$root.ExpenseIO.PlantList,
optionsText: 'PlantDescription',
optionValue:'PlantCode',
value: ExpenseIO.SelectedPlant,
optionsCaption: 'Select Plant'
" style="width: 180px" required="required" ></select>
<span class="error">*</span></span>
<span>
<input id="plantCode" required="required" data-bind="value:$root.ExpenseIO.SelectedPlant().PlantCode" readonly="true" class="readOnlyField" style="width: 82px" /><span class="error">*</span></span>
<span>Company</span>
<span>
<input id="companyCode" required="required" data-bind="value:ExpenseIO.SelectedPlant().CompanyCode" readonly="true" class="readOnlyField" style="width: 82px" /><span class="error">*</span></span>
<span>
<input id="companyDesc" required="required" data-bind="value:ExpenseIO.SelectedPlant().CompanyDescription" readonly="true" class="readOnlyField" style="width: 220px" /><span class="error">*</span></span>
</div>
答案 0 :(得分:0)
我不确定这是否会导致问题,但您需要提及optionsValue
而不是optionValue
所以请更新您的代码,如下所示:
<select data-bind="options:$root.ExpenseIO.PlantList,
optionsText: 'PlantDescription',
optionsValue:'PlantCode',
value: ExpenseIO.SelectedPlant,
optionsCaption: 'Select Plant'
" style="width: 180px" required="required" ></select>
查看淘汰文档以获取更多信息here。
我希望ExpenseIO.SelectedPlant
与value
select绑定的内容也存在于该上下文中,因为您在使用$root.ExpenseIO.SelectedPlant
绑定时提到了options
。