Question

Example of what I'd love to be able to do:

query.filter(function (person) {
    return person[this.field] == this.value;
}, {
    field: 'FirstName',
    value: 'Lea'
});

This throws an exception as of JayData 1.3.2. Note that hard-coding the property name with [] syntax works as expected (although not useful):

query.filter(function (person) {
    return person['FirstName'] == this.value;
}, {
    value: 'Lea'
});
  1. Is this possible without eval() trickery?
  2. If not, is there any kind of alternative?

Note: Using the OData provider, if that matters.

Était-ce utile?

La solution

yeah, it is not supported query.filter() has an alternative format:

  query.filter('it.something == this.something')

so with some string concat can achieve what you want

  query.filter('it.'+field+' == this.value', { value: 'Lea'})
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top