我需要访问这个Json对象
"savings": {
"1": {
"id": 111,
"name": "savings A"
},
"2": {
"id": 123,
"name": "savings B"
},
},
在多选菜单上显示:
<div class="form-group row">
<label class="col-sm-4 col-form-label text-right">Savings:</label>
<div class="col-sm-6">
<multiselect2
v-model="savings"
track-by="name"
label="name"
:options="savings_list"
:allow-empty="false"
:searchable="true">
</multiselect2>
</div>
</div>
////
data: () => ({savings_list: [], savings: null});
////
axios.get('/api/)
.then(response => {
this.savings_list = response.data.savings;
this.savings = this.savings_list.find(f => f.id>=0);}
我试着把存款申报为,但没有运气
savings_list: {array: {}}
我对其他数组也做了同样的处理,没有问题,这里的问题是我不知道如何使用Vue访问这个Json对象。当我运行代码时,我会得到以下错误:
Invalid prop: type check failed for prop "options". Expected Array, got Object
[Vue warn]: Error in getter for watcher "filteredOptions": "TypeError: this.options.concat is not a function"
我已经试着解决这个问题好几个小时了,任何帮助都是非常受欢迎的。
最终您可以尝试这个
.then(response => {
let new_savings_list = [];
for(saving in response.data.savings){
new_savings_list.push(response.data.savings[saving]);
}
this.savings_list = new_savings_list;```