人生若只如初见

JS数组和VUE利用filter(filters)实现数据过滤

电脑版发表于:2020/10/10 14:21

先说JS的语法
 array.filter(function(currentValue,index,arr), thisValue)

thisValue  可选 (不是必须)。对象作为该执行回调时使用,传递给函数,用作"this"的值。如果省略了thisValue , "this"的值为"undefined"

实际代码

            var NewArry = ArrList.filter(function (item) {

              此时的  item 就是当前list的对象     
                    return item.age > 10;      

              });


注意 filter 不会改变原始数组, 返回的是一个新数组  也不会对空数组进行检测

Vue 用法

首先定义

                  filters: {

                        capitalize: function (value) { 

                            return value.charAt(0).toUpperCase() + value.slice(1)

                        }

                    }

使用


 < !--在双花括号中 -->

               {{ message | capitalize } }

Vue官方地址 https://cn.vuejs.org/v2/guide/filters.html


关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢