AngularJS - 选择带有连接文本的文本

时间:2014-02-10 07:59:54

标签: javascript angularjs angularjs-scope

你能告诉我,如何选择这样的选择:

<select ng-model="model.user" ng-options="user._id as user.title for user in users">
    <option value="43f01">John Doe - Administrator</option>
    <option value="43f02">Adam Smith - Superviser</option>
</select>

来自这些数据:

[
    { "name" : "John Doe", "title" : "Administrator", "_id":"43f01"},
    { "name" : "Adam Smith", "title" : "Superviser", "_id":"43f02"},
]

任何建议都非常感谢。

1 个答案:

答案 0 :(得分:2)

ng-options接受选项文本的角度表达式,你可以在那里创建字符串

<select ng-model="model.user" ng-options="user._id as (user.name + ' - ' + user.title) for user in users">