【发布时间】:2016-05-06 00:32:00
【问题描述】:
我正在使用对我的数据库的调用来检索一些结果并将它们推送到一个数组中。但是,当我console.log(this.activeBeers) 时,我没有得到一个数组而是一个对象。我怎样才能得到一个普通数组而不是一个对象?
Vue.component('beers', {
template: '#beers-template',
data: function() {
return {
activeBeers: []
}
},
ready: function() {
function getActiveBeers(array, ajax) {
ajax.get('/getbeers/' + $('input#bar-id').val()).then(function (response) {
$.each(response.data, function(key, value) {
array.push(value.id);
});
}, function (response) {
console.log('error getting beers from the pivot table');
});
return array;
}
console.log(this.activeBeers = getActiveBeers(this.activeBeers, this.$http));
},
props: ['beers']
});
【问题讨论】:
标签: javascript jquery arrays vue.js vue-resource