【发布时间】:2021-01-21 12:58:23
【问题描述】:
如何过滤我的 JSON 数据数组:
这是我的标记:
<div v-if="vacciCounter">
<b-card no-body class="mb-2" v-for="(stateObject, state) in filteredList" v-bind:key="state">
<div style="margin:10px 10px 10px 10px;">
<h5>{{ state }}</h5>
这是我的功能:
computed: {
filteredList() {
if (this.vacciResults.length > 0) {
return this.vacciResults.filter(entry => {
return entry.state.toLowerCase().includes(this.searchstring.toLowerCase())
});
}
},
getStates() {
return this.vacciResults; // assuming that you have stored the response in a variable called 'output' defined in the data section
}
这是我获取 JSON 数据的 API 函数:vacciResults 正在获取状态。
fetch(vacciURL, {
method: 'get',
headers: {
}
}).then(res => res.json())
.then(res => {
this.status = '';
this.searchBtnDisabled = false;
this.vacciCounter = res.vaccinated;
this.vacciResults = res.states;
【问题讨论】:
-
vacciResults ...那是你的响应对象吗?
-
是的,这是响应对象:this.vacciResults = res.states;
-
在您的问题中也添加该代码
标签: javascript vue.js