【发布时间】:2019-12-23 15:33:59
【问题描述】:
更新 下面是我使用 axios 通过 API 得到的 json。
bannerData= [
{
"id": 118,
"title": "Geruchsbel\u00e4stigung",
"location": "DOR",
"pressInformation": [
{
"id": 257,
"title": "Chemi257"
},
{
"id": 256,
"title": "Chemi256",
}
]
},
{
"id": 144,
"title": "Testing Stage",
"location": "LEV",
"pressInformation": [
{
"id": 254,
"title": "Chemi254",
},
{
"id": 261,
"title": "Chemi261",
}
]
}
]
computed: {
orderedUsers: function() {
this.secondSubBanner = [];
for (let i = 0; i < this.bannerData.length; i++) {
this.subBanner = this.bannerData[i].pressInformation;
for (let j = 0; j < this.subBanner.length; j++) {
this.secondSubBanner.push(this.subBanner[j].id);
console.log(this.secondSubBanner); // output: 257, 256, 254,261
}
}
return this.secondSubBanner;
},
sortedArray() {
let v = this.orderedUsers.sort();
console.log(v); // output: 254, 256, 257, 261
return _.orderBy(this.bannerData, v)
}
sortedArray 正在使用 sort() 按顺序打印 id。但它不能对 Json 属性进行排序,这取决于使用 _.orderBy()。谁能说我哪里做错了?
【问题讨论】:
-
_.orderBy()不是 Undersore / Lo-Dash 功能吗? -
是的,它是一个lodash函数,我已经导入了lodash库
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js"/> -
bannerData看起来像什么?为什么要将v作为第二个参数传递给orderBy? -
我已经更新了我的问题
-
@SreenivasuluGudipati 你的排序后想要的输出是什么?
标签: javascript vue.js vuejs2 lodash