Qq:为什么不是我的角度选项跟踪id工作 [英] Qq: why isn't my angular options track by id working
问题描述
我认为如果我通过id跟踪选项,那么模型int和id int应该对齐。
这就是我的意思:
我有一系列'选项':
$ scope.option = [
{Id: 0 ,文本:' Option0',Args: null },
{Id: 1 ,文字:' < span class =code-string> Option1',Args: null },
{Id: 2 ,文本:' Option2',Args: null },
];
这种结构,因为它是我用来填充选项框的基本类型
我还有一个对象需要一个int表示选项
$ scope.obj ect = {
标题:' 这是我对象'的精简版,
项目:[{column:' text',选择: 0 ,描述:' 这些也是假的。在ng-repeat表中表示'}]
在表格中我使用它如下:
...
< tr data-ng-repeat = < span class =code-keyword> object.Items中的项目 >
< ; td > {{item.column}} < / td >
< td > {{options [item.select] .Text}} < / td >
< td > {{item.description} } < / td >
< / tr >
...
看起来不错。当我连续点击时,'EditPanel'被填充并显示。
(此时我实际上有两个问题,但我会坚持使用最简单的这个QQ中的一个)
...
< 选择 data-ng-model = object.Items [selectedIndex] .select data-ng-options = option.Text for options in options track by option .Id > < /选择 >
...
但是选择选项始终处理作为选项类型。
我需要A:显示当前选择的选项文本,B:能够更改它。
我哪里错了?
我的尝试:
如上所述。选项列表始终具有'?'第一个选项:
< 选项 value = ? 已选择 < span class =code-keyword> = 已选择 > < / option >
如果我尝试进行更改,则选择从0变为 {Id:0,Text:'Option0', Args:null}
scope.option = [
{Id: 0 ,文本:' Option0',Args: null },
{Id: 1 ,文字:' Option1',Args: null },
{Id: 2 ,文本:' Option2',Args: null },
];
这种结构,因为它是我用于填充的基本类型选项框
我还有一个对象需要一个int表示选项
scope.object = {
标题:' 这是一个非常精简的我的对象的版本',
项目:[{column:' text',选择: 0 ,描述:' thes e也是假的。在ng-repeat表中表示'}]
在表格中我使用它如下:
...
< tr data-ng-repeat = < span class =code-keyword> object.Items中的项目 >
< ; td > {{item.column}} < / td >
< td > {{options [item.select] .Text}} < / td >
< td > {{item.description} } < / td >
< / tr >
...
看起来不错。当我连续点击时,'EditPanel'被填充并显示。
(此时我实际上有两个问题,但我会坚持使用最简单的这个QQ中的一个)
...
< 选择 data-ng-model = object.Items [selectedIndex] .select data-ng-options = option.Text for options in options track by option .Id > < /选择 >
...
但是选择选项始终处理作为选项类型。
我需要A:显示当前选择的选项文本,B:能够更改它。
我哪里错了?
我的尝试:
如上所述。选项列表始终具有'?'第一个选项:
< 选项 value = ? 已选择 < span class =code-keyword> = 已选择 > < / option >
如果我尝试进行更改,则选择从0变为{Id:0,Text:'Option0', Args:null}
I thought that if I track the option by id then the model int and id int should align.
Here's what I mean:
I have an array of 'Options':
$scope.option = [
{Id:0,Text:'Option0',Args:null},
{Id:1,Text:'Option1',Args:null},
{Id:2,Text:'Option2',Args:null},
];
The structure it that way because it is a basic type I use for populating option boxes
I also have an object that required an int representation of the option
$scope.object = {
Title: 'this is a very trimmed down version of my object',
Items:[{column:'text',select:0,description:'these are also fake. represented in an ng-repeat table'}]
In the table i use this like so:
...
<tr data-ng-repeat="item in object.Items">
<td>{{item.column}}</td>
<td>{{options[item.select].Text }}</td>
<td>{{item.description}}</td>
</tr>
...
which looks fine. When I click in a row, the 'EditPanel' is populated and shown.
(I actually have two issues at this point, but I'll stick with the simplest one in this QQ)
...
<select data-ng-model="object.Items[selectedIndex].select" data-ng-options="option.Text for option in options track by option.Id"></select>
...
But the select options are always treated as an Option type.
I need to A: Display the currently selected option text and B: be able to change it.
Where am I going wrong?
What I have tried:
As described above. The option list always has the '?' first option:
<option value="?" selected="selected"></option>
and if I try to make a change then the select changes from 0 to { Id: 0,Text: 'Option0',Args: null }
scope.option = [ {Id:0,Text:'Option0',Args:null}, {Id:1,Text:'Option1',Args:null}, {Id:2,Text:'Option2',Args:null}, ];
The structure it that way because it is a basic type I use for populating option boxes
I also have an object that required an int representation of the option
scope.object = { Title: 'this is a very trimmed down version of my object', Items:[{column:'text',select:0,description:'these are also fake. represented in an ng-repeat table'}]
In the table i use this like so:
... <tr data-ng-repeat="item in object.Items"> <td>{{item.column}}</td> <td>{{options[item.select].Text }}</td> <td>{{item.description}}</td> </tr> ...
which looks fine. When I click in a row, the 'EditPanel' is populated and shown.
(I actually have two issues at this point, but I'll stick with the simplest one in this QQ)
... <select data-ng-model="object.Items[selectedIndex].select" data-ng-options="option.Text for option in options track by option.Id"></select> ...
But the select options are always treated as an Option type.
I need to A: Display the currently selected option text and B: be able to change it.
Where am I going wrong?
What I have tried:
As described above. The option list always has the '?' first option:
<option value="?" selected="selected"></option>
and if I try to make a change then the select changes from 0 to{ Id: 0,Text: 'Option0',Args: null }
这篇关于Qq:为什么不是我的角度选项跟踪id工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!