gpt4 book ai didi

javascript - 通过键查找模型

转载 作者:行者123 更新时间:2023-11-28 08:13:33 24 4
gpt4 key购买 nike

我想从按键查询的模型中获取“行”。我怎样才能做到这一点?我正在寻找类似的东西

{{ mysettings.backcolor | searchby(datuak.ref) }} 或类似的东西。

事实是,我有一个包含数据的模型,以及另一个包含背景和前色信息的模型。它们之间的关系是“ref”列。

打印表格时,在ng-repeat上,我想通过id查询它来获取前景色/背景色。

有什么帮助或线索吗?

我的 Controller 中有这两个模型:

$scope.mysettings = [
{ ref: '3CI00001', backcolor: '#000000', forecolor: '#ffffff' },
{ ref: '3CI00002', backcolor: '#5cb85c', forecolor: '#000000' }
];

这是另一个模型:

$scope.datuak = [
{
linea: '1',
egunak:[{
fetxa: '2014/05/19',
turnoak: [
{
turno: "1",
ordenes: [
{ ref: '3CI00001'},
{ of: 'OF000013'}
]
},
{
turno: "2",
ordenes: [
{ ref:'3CI00001'},
{ of:'112233'},
{ ref:'3CI00001'}
]
},
{
turno: "3",
ordenes: [
{ ref:'3CI00001'}
]
}
]},
{fetxa: '2014/05/20'},
{fetxa: '2014/05/21',
turnoak: [
{
turno: "1",
ordenes: [
{ ref: '3CI00001'},
{ of: 'OF200013'}
]
},
{
turno: "2",
ordenes: [
{ ref:'3CI00001'},
{ of:'OF232233'},
{ of:'OF289977'}
]
},
{
turno: "3",
ordenes: [
{ ref:'3CI00001'},
{ of:'OF200000'},
{ ref:'3CI00001'},
{ of:'OF200000'},
{ ref:'3CI00001'}
]
}
]},
{fetxa: '2014/05/22'},
{fetxa: '2014/05/23'},
{fetxa: '2014/05/24'},
{fetxa: '2014/05/25'}
]
},
{
linea: '2',
egunak:[
{ fetxa: '2014/05/19'},
{
fetxa: '2014/05/20',
turnoak: [
{
turno: "1",
ordenes: [
{ ref: '3CI00001'},
{ of: '2OF000013'}
]
},
{
turno: "2",
ordenes: [
{ ref:'3CI00001'},
{ of:'2OF2233'},
{ ref:'3CI00001'}
]
},
{
turno: "3",
ordenes: [
{ ref:'3CI00001'}
]
}
]},
{fetxa: '2014/05/21'},
{
fetxa: '2014/05/22',
turnoak: [
{
turno: "1",
ordenes: [
{ ref: '3CI00001'},
{ of: '2OF200013'}
]
},
{
turno: "2",
ordenes: [
{ ref:'3CI00001'},
{ of:'2OF232233'},
{ ref:'3CI00001'}
]
},
{
turno: "3",
ordenes: [
{ ref:'3CI00001'},
{ of:'2OF200000'},
{ ref:'3CI00001'},
{ of:'2OF200000'},
{ ref:'3CI00001'}
]
}
]},
{fetxa: '2014/05/23'},
{fetxa: '2014/05/24'},
{fetxa: '2014/05/25'}
]
}
];

对于这两个模型,我的看法是这样的:

        <tbody>
<tr ng-repeat="lineas in datuak">
<td class="tdlinea">Linea:{{ lineas.linea }}</td>
<td data-ng-repeat="nireindex in [0,1,2,3,4,5,6]">
<table class="table text-center table-condensed">
<thead>
<th>Mañana</th>
<th>Tarde</th>
<th>Noche</th>
</thead>
<tbody>
<tr>
<td>
<table>
<tr ng-repeat="orden in lineas.egunak[nireindex].turnoak[0].ordenes" ng-if="checkStatus(lineas.egunak[nireindex].fetxa,nireindex)">
<td>{{ orden.ref }} {{ orden.of }} </td>
</tr>
</table>
</td>
<td>
<table>
<tr ng-repeat="orden in lineas.egunak[nireindex].turnoak[1].ordenes" ng-if="checkStatus(lineas.egunak[nireindex].fetxa,nireindex)"><td>{{ orden.ref }} {{ orden.of }}</td></tr>
</table>
</td>
<td>
<table>
<tr ng-repeat="orden in lineas.egunak[nireindex].turnoak[2].ordenes" ng-if="checkStatus(lineas.egunak[nireindex].fetxa,nireindex)"><td>{{ orden.ref }} {{ orden.of }}</td></tr>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr> <!-- lineas -->
</tbody>

最佳答案

您可以查看 Angular js 过滤器过滤器:https://docs.angularjs.org/api/ng/filter/filter

如果您需要更进一步,您可以使用 array.filter() 方法创建自己的:

app.filter('searchBy', function() {
return function( array, prop , val ) {
// filter has polyfills for older browsers. Check underscore.js if needed
return array.filter( function(row) {
return row[prop] == val;
} );
// this returns an array. You can pick the first element with [0]
}
} );

然后在循环中使用它,如下所示:

{{ mySetting | searchBy : 'ref' : linea.ref }} 

关于javascript - 通过键查找模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23869618/

24 4 0
文章推荐: c++ - 优化 QPixmap 绘图
文章推荐: C++ 类重载 : is it possible to make compiler see which one to use based on template?
文章推荐: c++ - 如何更改下一个字符在 MFC 的编辑控件中的位置?
文章推荐: javascript - 使用 jQuery 的
内带有