[英]VueJs filtering by JSON
How can I filter the data to show the name? 如何过滤数据以显示名称?
I have card filtering by cites 我有被引证过滤的卡片
<div v-for="item in stationCityData">
<div v-for="option in filteredCity" style="background:#eee;padding: 20px">
<!-- <div v-for="option in item.children" style="background:#eee;padding: 20px"> -->
<Card :bordered="false">
<p slot="title">
{{ option.title }}
</p>
<p>
Content of no border type. Content of no border type. Content of no border type. Content of no border type.
</p>
</Card>
</div>
</div>
Here is a JSON 这是一个JSON
[
{
"title": "Mazowieckie",
"children": [
{
"title": "Warszawa",
"count": 10000
},
{
"title": "Otwock",
"count": 10600
}
]
}
]
And i need make a filtering by children.title 我需要按children.title进行过滤
I tried by this way: 我通过这种方式尝试过:
export default {
components: {
Header,
Footer,
Col,
Row
},
name: 'Index',
data () {
return {
stationCity: '',
stationCityData,
stationCitySearch: ''
}
},
computed: {
// Filtered by Cites
filteredCity: function () {
return this.stationCityData.filter((item) => {
let childrens = stationCityData.map(function (q) {
return q.children;
});
return item.childrens.match(this.stationCitySearch)
})
}
}
} }
but did not succeed Is there any way to do this? 但是没有成功有没有办法做到这一点? Filtering cards by children.title.
按children.title过滤卡片。 example by "Warszawa"
以“ Warszawa”为例
I know this is old so you might have worked this out. 我知道这很旧,所以您可能已经解决了。 This worked for me:
这为我工作:
data(){
return{
filterName:'Warszawa'
}
},
computed:{
filteredName(){
return this.titles
.filter((title)=>{
return item.title.match(this.filterName);
})
then 然后
<div v-for="item in filteredName"></div>
Granted, for me, I was calling a JSON object from an API but I assume you are doing the same. 当然,对我而言,我从API调用了JSON对象,但我想您也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.