简体   繁体   English

Vue.js 1x filterBy如何工作?

[英]How Vue.js 1x filterBy works?

I'd like to implement a filter in my app like the filterBY Vue.js provided in filters on 1x versions... 我想在我的应用中实现一个过滤器,例如1x版本的过滤器中提供的filterBY Vue.js ...

I'm trying to make a Computed Property to return an array with the objects that match with some string passed in a variable... But my aim is make something reusable and not give the attributes that searched every time... 我正在尝试使计算属性返回一个数组,该数组的对象与在变量中传递的某些字符串匹配...但是我的目标是使某些内容可重用,而不是每次都提供要搜索的属性...

Thanks for your attention guys 谢谢你们的关注

i had a help on facebook group Vue.js Brazil by the user Israel Sant'Anna that solved absolutely this demand, look the workaround: 我得到了以色列以色列Sant'Anna用户在Facebook组Vue.js Brazil上的帮助,它完全解决了这一需求,请查看解决方法:

var filterList = function(arr, filterTerm){
if (filterTerm === '') return arr
return deepFilter(arr, filterTerm)

} }

var deepFilter = function(arr, filterTerm){ return arr.filter(item => { var deepFilter = function(arr,filterTerm){return arr.filter(item => {

if (typeof item === 'object'){
        return deepFilter(Object.values(item), filterTerm).length > 0;
}

if(item.toString().indexOf(filterTerm)>=0){
    return true;
}

}) } })}

https://jsfiddle.net/igortrindade/3jr27cwm/6/ https://jsfiddle.net/igortrindade/3jr27cwm/6/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM