FilterBy exact match in vue.js

I have a list that I want to filter by an id value:

<li v-repeat="release.tracks | filterBy track_format in 'format_id'">

This works pretty nicely unless format_id is, e.g., 12, at which point I see all items with track_format 1 and 2 as well.

Is there a simple way of only showing items where the values constitute an exact match? I could abandon using numbers, but I feel like I'm going to carry on running into problems with formats like "LP" versus "Deluxe LP".

Answers


I encountered a similar issue, and wrote a drop-in replacement that does exact matching:

Vue.filter('exactFilterBy', function(array, needle, inKeyword, key) {
    return array.filter(function(item) {
        return item[key] == needle;
    });
});

Hope that helps!


Well, here's a way I just came up with, using a custom filter, that works (I'd still like to know if this kind of thing is the right sort of approach though):

Vue.filter('matching_format_id', function(value, format_id) {
   return value.filter(function(item) {
       return item.format_id === parseInt(format_id);
   });
});

<li v-repeat="release.tracks | matching_format_id track_format">

ETA: Actually, that didn't work so well, changes to release tracks were not triggering any kind of update in the view. Next tack, trying to filter with a computed property:

computed: {
       filteredTracks: function() {
           return this.release.tracks.filter(function (track) {
               return track.format_id === parseInt(vm.track_format);
           });
       }
   },

<li v-repeat="filteredTracks">

Looks promising so far, but that's what I thought about the last idea...


Need Your Help

SQL Server insertion performance

sql-server database-performance clustered-index insert-statement database-fragmentation

Let's suppose I have the following table with a clustered index on a column (say, a)

Limit size of Subversion repository

svn

Hi I'd like to limit the size of my repository by specifying a maximum size, however I cannot find any information on doing so. Is this technically possible?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.