我有以下对象数组:
document.addEventListener("DOMContentLoaded", function() {
var chart1 = new Highcharts.Chart({
chart: {
type: 'pie',
renderTo: 'container'
},
title: {
verticalAlign: 'middle',
floating: true,
text: 'CENTERED<br>TEXT'
},
plotOptions: {
pie: {
innerSize: '50%',
dataLabels: {
align: 'right',
distance: 10,
connectorWidth: 0
}
}
},
series: [{
data: [
['Firefox', 44.2],
['IE7', 26.6],
['IE6', 20],
['Chrome', 3.1],
['Other', 5.4]
]
}]
});
});
如何根据arr1标题的值对arr2进行排序?
所需的输出为:
arr1 = [{chart: {field: "test", title: "ABC", type: 0}}, {chart: {field: "test", title: "123", type: 1}}, {chart: {field: "test", title: "XYZ", type: 2}}]
arr2 = [{Name: "XYZ"}, {Name: "ABC"}, {Name: "123"}]
答案 0 :(得分:4)
答案 1 :(得分:2)
不是对arr2进行排序,而是根据arr1中的值为其分配新值:
DropDownList
答案 2 :(得分:1)
您可以将Map
用于索引。
var array1 = [{ chart: { field: "test", title: "ABC", type: 0 } }, { chart: { field: "test", title: "123", type: 1 } }, { chart: { field: "test", title: "XYZ", type: 2 } }],
array2 = [{ Name: "XYZ" }, { Name: "ABC" }, { Name: "123" }],
indices = new Map(array1.map(({ chart: { title }}, i) => [title, i]));
array2.sort(({ Name: a }, { Name: b }) => indices.get(a) - indices.get(b));
console.log(array2);
.as-console-wrapper { max-height: 100% !important; top: 0; }
答案 3 :(得分:-1)
只需从arr1创建一个新的arr2数组。
return CGSize(width: (collectionView.frame.width / 2) - 10, height: 220)
谢谢。
答案 4 :(得分:-1)
尝试以下解决方案
TouchableOpacity