Angular + Ionic,ng-options在选择选项中实现值标记

时间:2014-11-29 15:03:12

标签: angularjs ionic-framework

我在ng-options上使用<select>ng-options="item.model for item in prodataSelect | unique:'model' "

但我希望生成的选项的<value=""标记包含item.id,而不是ng-options使用的自动增量值。

如何实现这一目标?

HTML:

<select id = "chosenmodel" class="button button-full button-dark" ng-model="selectedModel" ng-options="item.model for item in prodataSelect | unique:'model' "> 
  <option value="">Select a Model</option>
</select>

<a id="submitbutton" class="button button-block button-dark ui-btn ui-btn-b ui-corner-all" ng-click='launchCompute()' href="#/app/compute/result">Compute my board</a>

prodataSelect中的每个项目都是一个对象:

{
  brand: "John",
  fun: "0",
  id: 1
},
{
  brand: "you",
  fun: "0",
  id: 185
},
{
  brand: "Ark",
  fun: "0",
  id: 17
},

2 个答案:

答案 0 :(得分:1)

使用以下语法

       `ng-options="item.id as item.model for item in prodataSelect"`

详细了解here

答案 1 :(得分:0)

使用&#34;按项目跟踪&#34; 将选项值设置为id

ng-options="item.id as item.model for item in prodataSelect track by item.id"