如何在下拉列表中仅存储 ID Bootstrap
How to store only ID in dropdown Bootstrap
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Section Id</label>
<div class="col-sm-10">
<select ng-model="product.sectionId" class="form-control" ng-options="section.name for section in sections track by section.id">
</select>
</div>
</div>
这是我的代码,我通过 JSON 和 section has id,name
填充 sections
对象。我只想在我的 product.sectionId
中存储 section.id
但它存储了部分 ID 和名称,如下所示
"sectionId":{"id":"Iron Man","name":"Superman"}
。我只想存储 id。有没有办法做到这一点。我是 bootstrap 和 angularjs 的新手,请帮助我。谢谢
将您的 ng-option
更改为
标记
ng-options="section.id as section.name for section in sections"
这将 section.name
和 select section.id
当您 select 任何选项时。
Do not use select as and track by in the same expression. They are not
designed to work together.
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Section Id</label>
<div class="col-sm-10">
<select ng-model="product.sectionId" class="form-control" ng-options="section.name for section in sections track by section.id">
</select>
</div>
</div>
这是我的代码,我通过 JSON 和 section has id,name
填充 sections
对象。我只想在我的 product.sectionId
中存储 section.id
但它存储了部分 ID 和名称,如下所示
"sectionId":{"id":"Iron Man","name":"Superman"}
。我只想存储 id。有没有办法做到这一点。我是 bootstrap 和 angularjs 的新手,请帮助我。谢谢
将您的 ng-option
更改为
标记
ng-options="section.id as section.name for section in sections"
这将 section.name
和 select section.id
当您 select 任何选项时。
Do not use select as and track by in the same expression. They are not designed to work together.