[英]Angularjs populating corresponding values for selected option in dropdown
I have data being passed to my view in following format 我有以下格式的数据被传递到我的视图
id name color type 1 Ford red sdean 2. Nisan blue truck ........ ID名称颜色类型1福特红色轿车2.尼桑蓝色卡车........
Following dropdown populates it by name 以下下拉列表按名称填充
<tr ng-repeat="p in allautos">
<td>
<select ng-model="p.id" ng-options="c.id as c.name for c in records"></select>
</td>
<td>
<input type="text" ng-model=p.color />
</td>
<td>
<input type="text" ng-model=p.type />
</td>
</tr>
What I am trying to do is when name is selected in the drop down I want corresponding values to populate in the input fields of color and type. 我要尝试的是在下拉列表中选择名称时,我希望在颜色和类型的输入字段中填充相应的值。 Please let me know the best way to achieve that.
请让我知道实现此目标的最佳方法。 Thanks
谢谢
I think you are looking for this: 我认为您正在寻找:
<select ng-model="p" ng-options="c.name for c in records track by c.id"></select>
http://plnkr.co/edit/m9ubFrYdAgPXMGhfri79?p=preview http://plnkr.co/edit/m9ubFrYdAgPXMGhfri79?p=preview
This uses a tracking expression to help angular to match the auto in the option array. 这使用跟踪表达式来帮助角度匹配选项数组中的auto。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.