angularJS:嵌套ng重复,orderBy不工作
我正在与angular合作,尝试在嵌套的ng重复上使用orderBy(在两个重复上),但没有成功。请看一看: 以下是我的看法:angularJS:嵌套ng重复,orderBy不工作,angularjs,Angularjs,我正在与angular合作,尝试在嵌套的ng重复上使用orderBy(在两个重复上),但没有成功。请看一看: 以下是我的看法: <article class="unaTienda" ng-repeat="tienda in resumenesRondaInventariosPorTienda | orderBy: ID_CO" > <h3 class='bold'>{{tienda[0][0].nombreTienda}}</h3> &
<article class="unaTienda"
ng-repeat="tienda in resumenesRondaInventariosPorTienda | orderBy: ID_CO" >
<h3 class='bold'>{{tienda[0][0].nombreTienda}}</h3>
<article class="unDocumento" ng-repeat="documento in tienda[$index]" >
<h3>{{documento.tipoDocumento}} {{documento.numeroDocumento}}</h3>
</article>
</article>
您的
$scope.resumenesRondaInventariosPorTienda
是一个对象,它应该是一个数组
重新操作数据
$scope.final = [];
for(var x in $scope.resumenesRondaInventariosPorTienda)
{
$scope.final.push($scope.resumenesRondaInventariosPorTienda[x]);
}
那么在你看来应该是这样的
<article ng-repeat="tienda in final | orderBy: tienda[$index].ID_CO" >
<article class="unDocumento" ng-repeat="documento in tienda | filter:busqueda" >
<h3>{{documento.tipoDocumento}} {{documento.numeroDocumento}}</h3>
</article>
</article>
{{documento.tipoDocumento}{{documento.numeroDocumento}}
John说得对,最好先将对象数据放入数组,然后在标记中排序(更简单)。我是在假设你不能弄乱数据结构的情况下操作的
所以!如果您需要执行自定义筛选功能,请执行以下操作:
//我喜欢按照John Papa风格指南将我的JS文件包装在iLife中
(功能(){
“严格使用”;
设app=angular.module('myApp',[]);
app.filter('resumenes',resumenesFunc);
应用程序控制器(“myCtrl”,myCtrlFunc);
myCtrlFunc.$inject=[“$scope”];
//自定义筛选函数
函数resumenesFunc(){
返回函数(resumenes){
设resumenesArr=[];
//将简历放入单个数组中
for(让resumenIndex在resumenes中){
设innerArr=resumenes[resumenIndex];
innerArr.forEach(r=>{
恢复发射推力(r);
})
}
返回resumenesArr.sort(函数(a,b){
返回a.numeroDocumento-b.numeroDocumento;
});
}
}
//控制器功能
函数myCtrlFunc($scope){
$scope.resumenesRondaInventariosPorTienda={
"1": [{
“身份证公司”:1,
“nombreTienda”:“UNICENTRO CALI”,
“fechaDocumento”:“20160126”,
“tipoDocumento”:“如果”,
“数字文件”:1,
“大学”:-19,
“比索”:-213310
}, {
“身份证公司”:1,
“nombreTienda”:“UNICENTRO CALI”,
“fechaDocumento”:“20180423”,
“tipoDocumento”:“如果”,
“数字文件”:16,
“大学”:-2,
“比索”:-11485
}],
"2": [{
“ID_CO”:2,
“nombreTienda”:“CAICEDO广场”,
“fechaDocumento”:“20160115”,
“tipoDocumento”:“如果”,
“数字文件”:1,
“大学”:-8,
“比索”:84701
}, {
“ID_CO”:2,
“nombreTienda”:“CAICEDO广场”,
“fechaDocumento”:“20160223”,
“tipoDocumento”:“如果”,
“数字文件”:2,
“大学”:-25,
“比索”:-556909
}]
}
}
})()
AngularJS测试应用程序
文件。写(“”);
自定义筛选器-简历
{{tienda.tipoDocumento}{{tienda.numeroDocumento}}
您可能需要。|orderBy:'ID_CO'
不起作用,它是嵌套的当你需要一个带有排序方法的自定义过滤器时谢谢你,我5分钟前刚刚将它改为数组,实现了同样的事情。将应用您的代码来查看和检查它是否工作,谢谢
<article ng-repeat="tienda in final | orderBy: tienda[$index].ID_CO" >
<article class="unDocumento" ng-repeat="documento in tienda | filter:busqueda" >
<h3>{{documento.tipoDocumento}} {{documento.numeroDocumento}}</h3>
</article>
</article>