0

I am trying to filter an upshot RemoteDataSource. With the setFilter function I can pass in an array of filters, but at the moment there is no way of specifying whether I want to apply (filter1 AND filter2), or (filter1 OR filter2). Looking into the upshot.js code, it is clearly visible why:

$.each(query.filters, function (index, filter) {
    if (filterParameter) {
        filterParameter += " and ";
    }
    filterParameter += applyOperator(filter.property, filter.operator, filter.value);
});

As you can see, the "and" is hardcoded into upshot. Is there any other way of supporting "or" between filters, or will I have to manually modify things? And if have to modify, what is the best approach to take so that my modifications don't get discarded when I update to a newer version of upshot?

This is the same question as the one on the ASP.NET forums.

4

1 回答 1

0

我知道这是一个可怕的黑客,但你可以做到这一点

self.dataSource.setFilter({ 
    property: "(CustomerId eq 1) or (CustomerId eq 2) and true", 
    operator: "==", 
    value: true });

基本上,您只需要意识到结果过滤器是 OData $filter 之上的一个非常泄漏的抽象。因此,在“属性”中,您可以编写任何您想要的 OData 过滤器,只要您以“true==true”结尾即可

让我想起了 SQL 注入技术。我在我的博客http://bartjolling.blogspot.com/2012/04/building-single-page-apps-with-aspnet.html中介绍了 Upshot 中的数据操作

我的结论是,它距离真正的商业应用程序还很远。

于 2012-04-04T12:24:39.800 回答