I used foreach to build a data array based on id. Initially all went well, but something happened. I think I was incorrectly using forEach. But after I console.log the array, it looks fine. Here is my code.
const Thread = Vue.component('threadpage', function(resolve) {
$.get('templates/thread.html').done(function(template) {
resolve({
template: template,
data: function() {
return {
data: {
title: "Data Table Thread",
count: {},
list: {}
}
};
},
methods: {
GetData: function() {
var data = {
username: "example-username",
data: {
page: 0,
length: 10,
schedule: "desc"
}
};
var args = {
"data": JSON.stringify(data)
};
var params = $.param(args);
var url = "http://example-url";
var vm = this;
DoXhr(url, params, function(response) {
count = JSON.parse(response).data.count;
vm.data.count = count;
var result = [];
result_data = JSON.parse(response).data.data;
result_data.forEach(function(item) {
//console.log(item);
result[item._id] = {
_id: item._id
};
});
vm.data.list = result;
console.log(result);
});
}
},
created: function() {
this.GetData();
}
});
});
});
As in vuejs.org, I used v-for like this :
<tbody v-for="item in data.list">
<tr>
<td>
{{ item._id }}
</td>
</tr>
</tbody>
The results don't display anything. Is something wrong with my template syntax? What is wrong with the code?