angular.js - Mengenai arahan ng-options angularjs
PHPz
PHPz 2017-05-15 16:59:55
0
3
582

Saya menarik tatasusunan daripada pengawal melalui ajax, var fruits = ['apple', 'banana'], saya berharap dapat mencapai kesan berikut:

<select>
  <option value='apple'>苹果</option>
  <option value='banana'>香蕉</option>
</select>
<select ng-options="fruit for fruit in fruits">
</select>

Faham

<select ng-options="fruit for fruit in fruits">
  <option value="0" selected="selected" label="apple">apple</option>
  <option value="1" selected="selected" label="apple">banana</option>
</select>

Bagaimana untuk mengubah suai nilai nilai dengan mengubah suai teg ng-options?

PHPz
PHPz

学习是最好的投资!

membalas semua(3)
伊谢尔伦

Hanya gunakan pilihan ng-repeat...

Malah, terdapat penyelesaian:
http://stackoverflow.com/questions/12139152/how-to-set-the-value-property-in-angularjs-ng-options

大家讲道理

Cara menukar buah menjadi susunan objek

伊谢尔伦
var data = {"201":"活动1","202":"活动2","203":"活动3"}  

<select class="form-control" ng-model="activityId" ng-options="id as name for (id, name) in data" ></select>

var toys = [{"id":"11", "name":"玩具1"},{"id":"12", "name":"玩具2"},{"id":"13", "name":"玩具3"}];

<select class="form-control" ng-model="toyId" ng-options="toy.id as toy.title for toy in toys" required></select>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan