jayData complex filter evaluation

89 Views Asked by At

I am new to jayData and am trying to filter on an entity set. The filter needs to perform an complex evaluation beyond what I saw in the samples.

Here is a working sample of what I am trying to accomplish (the listView line isn't and is just there to show what I plan to do with the data):

function () {
                var weekday = moment().isoWeekday()-1;
                console.log(weekday);
                var de = leagueDB.DailyEvents.toArray(function (events) {
                    console.log(events);
                    var filtered = [];
                    for (var e = 0; e < events.length;e++) {
                        console.log(events[e]);
                        console.log(events[e].RecurrenceRule);
                        var rule = RRule.fromString(events[e].RecurrenceRule);
                        var ruleOptions = rule.options.byweekday;
                        var isDay = ruleOptions.indexOf(weekday);
                        console.log(ruleOptions, isDay);
                        if(isDay =! -1)
                        {
                            filtered.push(events[e]);
                        }
                    }
                    $("#listView").kendoListView({dataSource:filtered});
                });

Basically it is just evaluating a recurring rule string to see if the current day meets that criteria, if so add that event to the list for viewing.

But it blows up when I try to do this:

eventListLocal:leagueDB.DailyEvents.filter(function(e){
                console.log("The Weekday is:"+viewModel.weekday);
                console.log(e);
                console.log("The recurrence rule is:"+e.RecurrenceRule);
                var rruleOptions = viewModel.rruleOptions(e.RecurrenceRule);
                if (rruleOptions !== -1) {
                    return true;
                }

            }).asKendoDataSource()

The error that is generating is: Exception: Unable to resolve type:undefined

The thing is it seems to be occurring on "e" and the console logs like the event is not being passed in. However, I am not seeing a list either. In short I am really confused as to what is going on.

Any help would be appreciated. Thanks,

1

There are 1 best solutions below

0
Yaser Moradi On

You can't write filter expressions such as this.

When you write .filter(...), jaydata will parse your expression and then it will generate filter for underlying provider, for example where for webSql and $filter for oDataProvider.

Both JayData expression parser and the data provider itself should understand your filter.

Your filter is not suitable for this approach, because most of your codes are not familiar for jaydata expression parser and the underlying data provider, for example your console.log etc.

You can simplify your filter, or you should load all your data into an array, and then you can use filter method of array itself, there, you can write any filter you like, and your filter will work. Of course this has performance issue in some scenarios when your data set is large.

Read more on http://jaydata.org/tutorials/entityexpressions-the-heart-of-jaydata