Dynamic filtering of Vuejs

Source: Internet
Author: User

Want to pass Vuejs dynamic filter (here dynamic refers to the condition of the filter is dynamic change),

I've never found a good way.

The stupidest way of course is two two arrays, one as an array of views as the original copy array, so that when the filter conditions change

Dynamically copy the original array filtered results to the view array, which allows Vuejs to perceive our view array changes and then update the view

This is stupid, and the copy is a waste of time, the code below

<HTML><Head>    <Scriptsrc= "Http://cdn.bootcss.com/vue/2.1.4/vue.js"></Script></Head><Body>    <DivID= "App">        <!--<li v-for= "N in Even (persons)" >{{N.name}}</li> -        <Liv-for= "N in Personsview">{{N.name}}:: {{n.age}}</Li>        <inputtype= "text"V-model= "Age"placeholder= "Age" />    </Div></Body><Scripttype= "Text/javascript">    varapp= NewVue ({el:'#app', Data: {Age:0, persons: [{name:'Zhang San', Age: -}, {name:'John Doe', Age: +}, {name:'Harry', Age:Ten}], personsview:[{name:'Zhang San', Age: -}, {name:'John Doe', Age: +}, {name:'Harry', Age:Ten}]}, methods: {even:function(persons) {returnPersons.filter (function(p) {returnP.age>= Ten; })}, watch:{Age:function(val,oldval) {Console.log ('NEW:%s, old:%s', Val, oldval); Console.log ( This. Persons.filter (function(p) {returnP.age>=Val;                }). Slice ());  This. Personsview=  This. Persons.filter (function(p) {returnP.age>=Val;            }). Slice (); }                    }    });</Script></HTML>

Who has a better way of doing this, you gotta tell me.

Dynamic filtering of Vuejs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.