【发布时间】:2011-10-08 07:08:36
【问题描述】:
我正在使用敲除将对象列表绑定到select。对象类可以有任意数量的属性
<select id="TheProperty_City"
name="TheProperty_City"
class="required"
data-bind="options: cityList,
optionsText: 'Name',
value: selectedCity,
optionsCaption: '--select the city--'" />
这很好用,我可以使用viewModel.selectedCity().Name 或viewModel.selectedCity().Value 来加载子元素。
我的问题是 jQuery 验证。如果我离开上面的语句,即使在选择之后,jQuery 也不会重置错误。
我通过在绑定中指定optionsValue 来修复它,但随后selectedCity 返回标量值而不是整个对象。知道如何保留对象行为或以不同方式进行验证吗?
<select id="TheProperty_City"
name="TheProperty_City"
class="required"
data-bind="options: cityList,
optionsText: 'Name',
optionsValue: 'Value', //added the optionsValue
value: selectedCity,
optionsCaption: '--select the city--'" />
当未指定optionsValue 时,错误仍然存在:
这是我在 selectedCity 上的 Object Watch:
当指定optionsValue 时,这是selectedCity 上的对象监视:
【问题讨论】:
标签: jquery asp.net asp.net-mvc jquery-validate knockout.js