【发布时间】:2016-02-24 01:51:46
【问题描述】:
在我后面的代码中,我填写了一个 DropDownList 如下(使用 VB)
ddlCountries.DataSource = dt ' dt is DataTable with columns "CountryCode" and "CountryName"
ddlCountries.DataTextField = "CountryName"
ddlCountries.DataValueField = "CountryCode"
ddlCountries.DataBind()
ddlCountries.Attributes.Add("ng-model", "CountryName")
然后是客户端,我有一个选择标签,里面填满了来自服务器端的选项,如下所示:
<select ng-model="CountryName">
<option value="IN">India</option>
<option value="US">United States</option>
<option value="ML">Malaysia</option>
<!-- and other 200+ records -->
</select>
我不能在这里使用ng-options!现在,每当我从select 更改值时,我都会得到CountryName 为IN、US、ML 等。此外,我无法编辑选项的值,因为它们用于服务器端代码。
在这里,我希望 CountryName 改为 India、United States 或 Malaysia!我能做什么?
【问题讨论】:
-
<option value="India">India</option> <option value="United States">United States</option> -
不能那样做...@KalhanoToressPamuditha
-
没有一种干净的方式来做你想做的事。最好让服务器根据需要发送值。
-
为什么不能使用ng-options(从服务器获取国家列表并绑定)?
-
@RuchirGupta 这可能是因为您没有按照需要的方式使用它,或者您的数据结构不是您认为的那样。除非您向我们展示您是如何使用它的,否则我们很难猜出问题所在。
标签: javascript angularjs angular-ngmodel angularjs-ng-options angularjs-ng-model