每当我放置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>

最佳答案

我不确定这是否是导致问题的原因,但您需要提及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>


有关更多信息,请参见剔除文档。

我希望在该上下文中也存在与select的ExpenseIO.SelectedPlant绑定的value,因为您在与$root.ExpenseIO.SelectedPlant绑定时提到了options

08-18 11:11