2 回答

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊
我希望我理解了你的問題,所以你只需要訂購數(shù)據(jù)來呈現(xiàn)它,你不需要在你的商店訂購它?
要顯示有序數(shù)據(jù),您可以使用此計(jì)算函數(shù),希望對您有所幫助
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 會(huì)像
<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貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個(gè)贊
希望我沒有誤解您的問題,但基本上我會(huì)建議您以與您當(dāng)前相同的方式加載您的數(shù)據(jù)并在計(jì)算方法中處理排序。
這是假設(shè)批次和調(diào)度站的長度將始終為 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>
如果我誤解了什么或者您有任何疑問,請告訴我。
添加回答
舉報(bào)