AngularJS ng-option获取索引 [英] AngularJS ng-option get index

查看:354
本文介绍了AngularJS ng-option获取索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究的项目中使用播放列表选项,并且试图获取列表中所有视频的下拉列表.

I'm making a playlist option in the project I'm working on and I'm trying to get a dropdown for all the videos in the list.

这很容易

<select ng-options="vid.Id for vid in playList.Videos track by video.Id" ng-model="selected" class="browser-default"></select>

但是这显示了Id的下拉列表,但是现在我希望它在列表+1中显示位置;

but this shows a drop down of the Id's, but now I want it to show the position in the list +1;

因此,在播放视频5/15时,下拉菜单应显示1到15(而不是0到14),并且应选择5.

So when playing video 5/15 the drop down should show 1 to 15 (so not 0 to 14) and 5 should be selected.

关于如何完成此操作的任何想法?

any idea on how to accomplish this?

推荐答案

如果要将当前视频的索引显示为选项文本,则此ngOptions表达式应该可以解决问题:

If you want to display index of the current video as option text, then this ngOptions expression should do the trick:

ng-options="vid as playList.Videos.indexOf(vid)+1 for vid in playList.Videos track by video.Id"

此处的关键是您可以使用 Videos数组上的> 方法来计算当前视频索引,然后添加1.

The key here is that you can use indexOf method on Videos array to calculate current video index, and then add 1.

这篇关于AngularJS ng-option获取索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆