Javascript 检索具有角度的选定选项文本,而不仅仅是包含id的值
我想知道检索介于Javascript 检索具有角度的选定选项文本,而不仅仅是包含id的值,javascript,angularjs,model,Javascript,Angularjs,Model,我想知道检索介于和之间的文本的最佳方式是什么,因为分配给的模型只返回id <select class="form-control" ng-model="videos.playlist"> <option ng-repeat="playlist in playlists" value="@{{ playlist.id }}" ng-selected="savePlaylistName()"> @{{ playlist.name
和
之间的文本的最佳方式是什么,因为分配给
的模型只返回id
<select class="form-control" ng-model="videos.playlist">
<option ng-repeat="playlist in playlists" value="@{{ playlist.id }}"
ng-selected="savePlaylistName()">
@{{ playlist.name }}
</option>
</select>
@{{playlist.name}
如前所述,而且应该是,videos.playlist
包含playlist.id
,但是如何将playlist.name
也包含在变量中?我能想到的唯一一件事就是使用ng selected
,然后对其进行处理,但它比我期望和/或寻找的稍微复杂一些。那么,有什么想法可以轻松实现这一点吗
理想情况下,我会有一些类似于videos.playlist.id
和videos.playlist.name
,因为我还需要手头有id
。试试这个:
<select ng-model="videos.playlist" ng-options="playlist.id for playlist.name in playlists">
<option value="">-- choose playlist --</option>
</select>
--选择播放列表--
将ng选项与表达式一起使用:
<select ng-model="videos.playlist" ng-options="playlist.name for playlist in playlists">
<option value="">-- choose playlist --</option>
</select>
--选择播放列表--
playlist对象是将绑定到
视频的选定对象。playlist
感谢您的建议,但我需要id
和名称,一旦您有了id,就可以从playlist对象获取名称。