我正在制作一个我们创建了JSON的计划,如下面的
{
"cancelledWeeks": {
"1511548200": [
{
"match_id": "e06d20944182aa2b5ead43e8990e5985",
"reason": "chhj",
"round": 1,
"team1": "team_id_17101711595974",
"date": 1511548200,
"team1_color_code": "#1f1818",
"team1_name": "17October team",
"team2": "team_id_1710179490074",
"team2_color_code": "#302929",
"team2_name": "cms team 4",
"time": "6:30 PM"
},
{
"match_id": "4715cf8897663e5474feaa14ef396674",
"reason": "chhj",
"round": 1,
"team1": "team_id_17101712185745",
"date": 1511548200,
"team1_color_code": "#1f0606",
"team1_name": "october 19",
"team2": "team_id_1710179420033",
"team2_color_code": "#363cba",
"team2_name": "cms team 3",
"time": "7:05 PM"
}
],
"1513967400": [
{
"match_id": "1e916238a526644194daa263906c7a23",
"reason": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,",
"round": 5,
"team1": "team_id_1710179420033",
"date": 1513967400,
"team1_color_code": "#363cba",
"team1_name": "cms team 3",
"team2": "team_id_17101711595974",
"team2_color_code": "#1f1818",
"team2_name": "17October team",
"time": "6:30 PM"
},
{
"date": 1513967400,
"match_id": "91ec5c9469c55cdb7426a92c19a2309a",
"reason": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,",
"round": 5,
"team1": "team_id_17101711441450",
"team1_color_code": "#36ba63",
"team1_name": "web team 2",
"team2": "team_id_17101717102231",
"team2_color_code": "#faf352",
"team2_name": "Retest team 17",
"time": "7:05 PM"
}
]
},
"rainoutWeeks": {
"1514572200": [
{
"match_id": "e06d20944182aa2b5ead43e8990e5985",
"round": 1,
"team1": "team_id_17101711595974",
"date": 1514572200,
"team1_color_code": "#1f1818",
"team1_name": "17October team",
"team2": "team_id_1710179490074",
"team2_color_code": "#302929",
"team2_name": "cms team 4",
"time": "6:30 PM"
},
{
"match_id": "4715cf8897663e5474feaa14ef396674",
"round": 1,
"team1": "team_id_17101712185745",
"date": 1514572200,**strong text**
"team1_color_code": "#1f0606",
"team1_name": "october 19",
"team2": "team_id_1710179420033",
"team2_color_code": "#363cba",
"team2_name": "cms team 3",
"time": "7:05 PM"
}
]
},
"schedule": {
"1514448462": [
{
"match_id": "e06d20944182aa2b5ead43e8990e5985",
"round": 1,
"team1": "team_id_17101711595974",
"date": 1514448462,
"team1_color_code": "#1f1818",
"team1_name": "17October team",
"team2": "team_id_1710179490074",
"team2_color_code": "#302929",
"team2_name": "cms team 4",
"time": "6:30 PM"
},
{
"match_id": "4715cf8897663e5474feaa14ef396674",
"round": 1,
"team1": "team_id_17101712185745",
"date": 1514448462,
"team1_color_code": "#1f0606",
"team1_name": "october 19",
"team2": "team_id_1710179420033",
"team2_color_code": "#363cba",
"team2_name": "cms team 3",
"time": "7:05 PM"
}
]
}
}
我正在重复使用不同键的行,例如
<tr ng-repeat="schedule_data.schedule")
<tr ng-repeat="schedule_data.rainoutWeeks")
<tr ng-repeat="schedule_data.cancelledWeeks")
我想根据日期对所有行进行排序,但我无法合并数组,因为我正在使用与每种计划类型相对应的一些编辑操作,并且无法更改流程。
有没有适用于当前情况的解决方案?
答案 0 :(得分:0)
为此,您需要创建自定义过滤器 以下是您的解决方案的完整代码
如果你想改变订单而不是像这样传递false orderObjectBy:键:假
<li ng-repeat="(key,val) in schedule_data | orderObjectBy:key:true">
{{val}}
<br>
</li>
var app = angular.module("myApp", []);
app.filter('orderObjectBy', function() {
return function(items, field, reverse) {
var filtered = [];
var data = [];
angular.forEach(items, function(value, key) {
angular.forEach(value, function(subvalue, subkey) {
var obj = {"key":subkey,"value":key}
filtered.push(obj);
});
});
filtered.sort(function (a, b) {
return (a['key'] > b['key'] ? 1 : -1);
});
if(reverse) filtered.reverse();
var returnData = [];
angular.forEach(filtered, function(obj, key) {
returnData.push(items[obj['value']][obj['key']]);
});
return returnData;
};
});
app.controller("myCtrl", function($scope) {
$scope.schedule_data = {
"cancelledWeeks": {
"2": [
{
"match_id": "e06d20944182aa2b5ead43e8990e5985",
"reason": "chhj",
"round": 1,
"team1": "team_id_17101711595974",
"team1_captains": {
},
"team1_color_code": "#1f1818",
"team1_name": "17October team",
"team2": "team_id_1710179490074",
"team2_captains": {
},
"team2_color_code": "#302929",
"team2_name": "cms team 4",
"time": "6:30 PM"
},
{
"match_id": "4715cf8897663e5474feaa14ef396674",
"reason": "chhj",
"round": 1,
"team1": "team_id_17101712185745",
"team1_captains": {
},
"team1_color_code": "#1f0606",
"team1_name": "october 19",
"team2": "team_id_1710179420033",
"team2_captains": {
},
"team2_color_code": "#363cba",
"team2_name": "cms team 3",
"time": "7:05 PM"
}
],
"4": [
{
"match_id": "1e916238a526644194daa263906c7a23",
"reason": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,",
"round": 5,
"team1": "team_id_1710179420033",
"team1_captains": {
},
"team1_color_code": "#363cba",
"team1_name": "cms team 3",
"team2": "team_id_17101711595974",
"team2_captains": {
},
"team2_color_code": "#1f1818",
"team2_name": "17October team",
"time": "6:30 PM"
},
{
"date": 1513967400,
"location": "loc_id_17092712170130",
"match_id": "91ec5c9469c55cdb7426a92c19a2309a",
"reason": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,",
"round": 5,
"team1": "team_id_17101711441450",
"team1_captains": {
},
"team1_color_code": "#36ba63",
"team1_name": "web team 2",
"team2": "team_id_17101717102231",
"team2_captains": {
},
"team2_color_code": "#faf352",
"team2_name": "Retest team 17",
"time": "7:05 PM"
}
]
},
"rainoutWeeks": {
"5": [
{
"match_id": "e06d20944182aa2b5ead43e8990e5985",
"round": 1,
"team1": "team_id_17101711595974",
"team1_captains": {
},
"team1_color_code": "#1f1818",
"team1_name": "17October team",
"team2": "team_id_1710179490074",
"team2_captains": {
},
"team2_color_code": "#302929",
"team2_name": "cms team 4",
"time": "6:30 PM"
},
{
"match_id": "4715cf8897663e5474feaa14ef396674",
"round": 1,
"team1": "team_id_17101712185745",
"team1_captains": {
},
"team1_color_code": "#1f0606",
"team1_name": "october 19",
"team2": "team_id_1710179420033",
"team2_captains": {
},
"team2_color_code": "#363cba",
"team2_name": "cms team 3",
"time": "7:05 PM"
}
]
},
"schedule": {
"1": [
{
"match_id": "e06d20944182aa2b5ead43e8990e5985",
"round": 1,
"team1": "team_id_17101711595974",
"team1_captains": {
},
"team1_color_code": "#1f1818",
"team1_name": "17October team",
"team2": "team_id_1710179490074",
"team2_captains": {
},
"team2_color_code": "#302929",
"team2_name": "cms team 4",
"time": "6:30 PM"
},
{
"match_id": "4715cf8897663e5474feaa14ef396674",
"round": 1,
"team1": "team_id_17101712185745",
"team1_captains": {
},
"team1_color_code": "#1f0606",
"team1_name": "october 19",
"team2": "team_id_1710179420033",
"team2_captains": {
},
"team2_color_code": "#363cba",
"team2_name": "cms team 3",
"time": "7:05 PM"
}
]
}
};
});