如何设置NG选项preselected价值?如何设置、选项、价值、NG

由网友(人群恐惧症)分享简介:我有一个应该在下拉列表中选择城市ID,但我不能老是设法preSELECT它。我应该指令选择它或有任何其他方式? <选择NG模型=cityIdNG选项=city.name城市在城市>< /选择> 解决方案 编辑NG-选项是: city.id作为city.name城市在城市 如果您获取城市和不知道...

我有一个应该在下拉列表中选择城市ID,但我不能老是设法preSELECT它。我应该指令选择它或有任何其他方式?

 <选择NG模型=cityIdNG选项=city.name城市在城市>< /选择> 

解决方案

编辑NG-选项是:

  city.id作为city.name城市在城市 

如果您获取城市和不知道的ID你可以在你的JavaScript函数的成功说(它返回城市):

  $ scope.cityId = the_cities [0] .ID 
今日头条搜索广告使用攻略

设置为第一选择否则你可能只是说:

  $ scope.cityId = 1; //或存在什么 

I have id from the city that is supposed to be selected in dropdown list, but I can`t manage to preselect it. Should I select it from directive or is there any other way?

<select  ng-model="cityId" ng-options="city.name for city in cities"></select>

解决方案

Edit your ng-options to this:

city.id as city.name for city in cities

if you fetch the cities and don't know the ID's you could say in your javascript success function (which returns the cities):

$scope.cityId = the_cities[0].ID

to set the first as selected Else you could just say:

$scope.cityId = 1; //or anything that exists

阅读全文

相关推荐

最新文章