【发布时间】:2017-10-28 14:18:37
【问题描述】:
我正在尝试从 JSON 文件 a.json 中对 JSON 数组进行排序。
数组是这样来的:
{"data":
[
{"exception":"",
"name":"Data Server1",
"alias":"TOR-Server",
"delayed":"NO",
},
{"exception":"",
"name":"Data Server2",
"alias":"FRA-Server",
"delayed":"NO",
}
]
我需要按“别名”对数据进行排序,来自带有 Vue JS 的 JSON 文件。
这是我在 Vue JS 中显示的 Javascript 代码
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
json: null
},
computed: {
sorted: function() {
setTimeout(function() {
var app = this.app.json
if (app.length >= 6)
return app;
}, 5000);
}
},
methods: {
toggleClass(){
if (this.failed == true){
this.failed = false;
}
else
{
this.failed = true;
}
}
}
但是 Sorted 函数不起作用,如果我尝试在 sorted 数组中显示服务器,我会收到一个空白页。
而我在 HTML 页面中的 for 循环是:
<div class="mainbutton" v-for="(server, index) in json.data ">
希望这是有道理的,我可以让它工作。
【问题讨论】:
标签: javascript arrays json sorting vuejs2