2 回答
TA贡献1839条经验 获得超15个赞
我希望我理解了你的问题,所以你只需要订购数据来呈现它,你不需要在你的商店订购它?
要显示有序数据,您可以使用此计算函数,希望对您有所帮助
computed:{
...mapGetters(["allBatches"]),
orderApplications(){
let copieBatches = JSON.parse(JSON.stringify(this.allBatches));
copieBatches.forEach(batches => {
batches.dispatchstation.forEach(dispatchstation=>{
dispatchstation.applications.sort()
})
});
return copieBatches
}
}
你的 HTML 会像
<div>
<div v-for="batches in orderApplications">
<div
v-for="dispatchstation in batches.dispatchstation"
:key="dispatchstation.id">
<div v-for="apps in dispatchstation.applications">
<div>{{apps}}</div>
</div>
</div>
</div>
</div>
TA贡献1886条经验 获得超2个赞
希望我没有误解您的问题,但基本上我会建议您以与您当前相同的方式加载您的数据并在计算方法中处理排序。
这是假设批次和调度站的长度将始终为 1。
new Vue({
el: "#app",
data: {
allBatches: null
},
computed: {
batchesSorted() {
if (!this.allBatches) return {}
const output = this.allBatches.batches[0].dispatchstation[0].applications;
output.sort((a, b) => {
return parseInt(a) - parseInt(b)
})
return output
}
},
async created() {
// Equivelent to ...mapGetters(["allBatches"]) for the example
this.allBatches = {
"batches": [{
"dispatchstation": [{
"applications": [
"384752387450",
"456345634563",
"345634563456",
"567845362334",
"567456745677",
"456734562457",
"789676545365",
"456456445556",
"224563456345",
"456878656467",
"053452345344",
"045440545455",
"045454545204",
"000014546546",
"032116876846",
"546521302151",
"035649874877",
"986765151231",
"653468463854",
"653853121324",
"000145456555"
]
}]
}]
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div v-for="(item, key) in batchesSorted" :key="key">
{{ item }}
</div>
</div>
如果我误解了什么或者您有任何疑问,请告诉我。
添加回答
举报