获取AngularJS select中选定元素的属性
我有一个简单的问题要问AngularJS select。我正在使用对象的数组创建选择标记获取AngularJS select中选定元素的属性,angularjs,Angularjs,我有一个简单的问题要问AngularJS select。我正在使用对象的数组创建选择标记 <select data-ng-model="selectedPipeLine" name="selectedPipeLine" required="required" data-ng-options="obj.id as obj.name for obj in pipeLinesList"> </select> {{selectedPipeLine}} {{se
<select data-ng-model="selectedPipeLine" name="selectedPipeLine" required="required" data-ng-options="obj.id as obj.name for obj in pipeLinesList">
</select>
{{selectedPipeLine}}
{{selectedPipeLine}}
当用户从此选择中选择时,所选idobj.id
将显示在选择附近。
但数组中的对象具有其他属性。如何显示其他属性?
{{pipeLinesList[selectedPipeLine]}
不工作
如果有任何想法和建议,我将不胜感激
以下是JSFIDLE:
我想获取otherProperty
的值
致以最良好的祝愿 在你的情况下,我想你可以这样改变你的表情:
data-ng-options="obj.name for obj in pipeLinesList"
在这种情况下,您的selectedPipeLine
不是id
,而是对当前选定对象的引用=>您可以自由访问此对象的任何属性。像这样:
<select data-ng-model="selectedPipeLine" name="selectedPipeLine" required="required" data-ng-options="obj.name for obj in pipeLinesList">
</select>
{{selectedPipeLine.id}}
{{selectedPipeLine.otherProperty}}
{{selectedPipeLine.id}
{{selectedPipeLine.otherProperty}
你能用你的尝试创造一个基本的小提琴吗?