本文介绍了AngularJS - ngOptions数字排序按标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有网友上传的表格数据,那么我允许它被插入一路前他们解析它。

I have users upload tabular data, then I allow them to parse it before it gets inserted all the way.

例如一个用户可以上传

ID, NAME, PASSWORD, ADDRESS, EMAIL
10, Tim, foo, 123 S Main, [email protected]
11, Withers, foo, 123 S Main, [email protected]
//ETC//

和其他用户可能不同格式的他们的数据:

And another user may format their data differently:

FIRST_NAME, LAST_NAME, ID, PASSWORD, EMAIL
Tim, Withers, 10, 123, [email protected]
//You get the idea...

我的应用程序需要的数据,并允许用户指定哪些列有最后上传到服务器之前的必要信息:

My app takes the data and allows the user to specify which columns have the necessary information before the final upload to the server:

Column 0 => ID
Column 4 => Email
Column 2 => Password

我想用一个选择来限制用户的输入:

Which column is the First Name? 
<select 
    ng-options="k as k for (k,v) in uploadData.row[0]" 
    ng-model="columnData.firstName">
</select>

这个伟大的工程,但如果他们有超过9列选择框看起来是这样的:

This works great, but if they have more than 9 columns the select box looks like this:

0
1
10
11
12
13
2
3
4
5
6
7
8
9

我如何确保它显示1-13连续?有另一种方式来创建选项选择特定的长度?

How do I make sure that it is displayed 1-13 consecutively? Is there another way to create a select with options for a specific length?

编辑:拨弄问题:

推荐答案

这是完全OK了选项可使用NG-重复标记生成一个选择框的选项。
使用 ngRepeat 至少有两种方式,以满足您的要求。

It is perfectly OK to use ng-repeat over option tag to generate options for a select box.Using ngRepeatthere are at least two ways to meet your requirements.

<select ng-model="selected">
  <option ng-repeat="(key, friend) in friends" value="{{key}}">{{key}}</option>
</select>

ngRepeat迭代器的

使用 $指数属性

Using $index property of ngRepeat iterator

<select ng-model="selected">
  <option ng-repeat="friend in friends" value="{{$index}}">{{$index}}</option>
</select>

由于 ngRepeat 迭代器从零开始,这两个例子会产生范围0-12选项。为了使它的显示选项1-13,你可以简单地添加 +1 在每次迭代:

Since ngRepeat iterator is zero-based, these two examples will produce options in range 0-12. To make it display options 1-13 you can simply add +1on each iteration:

<option ng-repeat="(key, friend) in friends" value="{{key+1}}">{{key+1}}</option>

<option ng-repeat="friend in friends" value="{{$index+1}}">{{$index+1}}</option>

这篇关于AngularJS - ngOptions数字排序按标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:00