Closed vulpineronin closed 9 years ago
You can run into similar problems with SQL sometimes. It is true that it isn't doing what is expected but the actual logic turns into "return all records that don't match the first valueArray value OR don't match the second valueArray value..."and so on.
I think this will do what you want, but we may want to think about adding some kind of formal NOT IN support to the library.
taffyTable(function () {
for (var dex = 0;dex<valueArray.length;dex++) {
if (valueArray[dex] === this.id)
{
return false;
}
}
return true;
})
Thanks, and yes that works but can actually be shrunk. I currently have it running off js indexOf in the function.
taffyTable(function(){ return (valueArray.indexOf(this.id) == -1) ? true : false; }).get();
Just wanted to let you know about this as I came across it today in our application. It may just be due to the fact that we are having to use an array instead of a single value (as to why the bang may not be functioning for us) but I have not tested it against single values at this point.
Yeah, as I recall this was supported in 1.X version of Taffy but with the shift I opted to make arrays always function as logical OR statements knowing this use case wouldn't be supported but thinking it less confusing. Probably need a "contains" and "!contains" operator.
Perhaps I am missing something, but I see no built in way to do a negative compare. If I use taffyTable({id:{'==',valueArray}}).order('field asec').get(); then it will pull all rows where id matches a value in the valueArray array. What I need to do though is get the list of rows where id != valueArray, i.e. all rows where the id value is not in the array. I find nothing in the documentations about a negative comparison and the only way I am currently seeing to achieve this is to iterate over every row and check myself, which negates the purpose of using Taffy in the first place. If I am missing something then please let me know, otherwise I would say that this is a severe lack to have multiple ways to do a positive compare but no way to check the inverse.
Edit: Just wanted to clarify, I do see in the docs about using the bang (!) with a quoted comparison. But when this is used on the dataset it returns all results. i.e.
taffyTable({id:{"==",valueArray}}).order('field asec').get(); => returns only records that have an id that is within the valueArray
affyTable({id:{"!==",valueArray}}).order('field asec').get(); => returns all records in taffyTable, ones that id is in valueArray and ones that are not.