Closed oleynikd closed 9 years ago
If you need to access a filtered result, it's often better to use a computed property:
computed: {
filteredChannels: function () {
var filter = Vue.filter('filterBy')
return filter(this.channels, this.searchText, 'name')
}
}
Then in your template, work with filteredChannels
directly.
For the enter key, just retrieve the item as this.filteredChannels[this.selectedItem]
.
Great! Thank you A LOT!!!
In case someone will try this, there's a little typo in @yyx990803 response. The right version is:
computed: {
filteredChannels: function () {
var filter = Vue.filter('filterBy')
return filter(this.channels, this.searchText, 'name')
}
}
Thank you once more! Worked like super magic!
oops, fixed typo ;)
Dear @yyx990803 is it a god idea to recreate var filter
everytime? Or this closure is called only once?
Thanks.
@oleynikd it's fine, the cost is negligible.
How can I get the length of an array and display it in the View. Something like
<span v-text="users.length"></span>
I think I found a solution:
filters:{
count: function(value){
return value.length;
}
}
and in view:
<span v-text="users | count"></span>
This worked for me. Thanks :)
Hi,
I'm using Vue for displaying search results. Everything is super cool! For search results output I use:
channels
is array like:Works great!
But I need to make this lis selectable by up/down keys (a common task for search lists). I use this:
And on repeat model I add
v-class
:This also works, but:
selectedItem
has reached the end of the list? How can I know the length of filtered array?Thanks.