Data binding 将sap.ui.table.table的行绑定到sap.ui.model.odata.v2。ODataModel的方法-url中缺少参数

Data binding 将sap.ui.table.table的行绑定到sap.ui.model.odata.v2。ODataModel的方法-url中缺少参数,data-binding,sapui5,url-parameters,Data Binding,Sapui5,Url Parameters,也许没必要告诉你,我一直在谷歌上搜索,查看文档和规范,并且测试了几天,但都没有成功 我试图实现的目标是:我希望将表中的行绑定到同一模型中的一个服务方法,该服务方法接受一个参数,过滤Contragents并返回一个IQueryable,而不是绑定到模型中名为Contragent的具体实体。我记得昨天读到一个stackoverflow问题——有人问,是否可以只使用ODataURL参数实现sql“in”子句。他们回答说,唯一的方法是构建一个字符串,格式为$filter=Name eq'test1'和N

也许没必要告诉你,我一直在谷歌上搜索,查看文档和规范,并且测试了几天,但都没有成功

我试图实现的目标是:我希望将表中的行绑定到同一模型中的一个服务方法,该服务方法接受一个参数,过滤Contragents并返回一个IQueryable,而不是绑定到模型中名为Contragent的具体实体。我记得昨天读到一个stackoverflow问题——有人问,是否可以只使用ODataURL参数实现sql“in”子句。他们回答说,唯一的方法是构建一个字符串,格式为$filter=Name eq'test1'和Name eq'test2',然后。。。。因此,我认为如果我能在我的OData服务中添加一个自定义方法会很好,在这里我可以轻松地使用C语言中的LINQ。我在OData文档中看到,不需要模型的实体,只需编写正确的URL就可以再次从这样的方法中查询数据。所以,基本上,这就是我想要的-将我的SAP表绑定到select*from Contragent,其中select Name from中的名称。。。使用我创建的OData服务

到目前为止我所做的工作:首先,我学习了如何向OData服务添加自定义服务方法。它看起来必须放在初始化服务的同一个类中:

public class MyService : EntityFrameworkDataService<MyEntities>
{
    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(DataServiceConfiguration config) {
        // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
        // Examples:
        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead | EntitySetRights.AllWrite);
        //https://debugmode.net/2012/01/13/how-to-work-with-custom-method-in-wcf-data-service/
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); // for the custom method to be accessible via the service
        config.UseVerboseErrors = true;
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
    }

    private MyEntities entities = new MyEntities();
    //https://docs.microsoft.com/en-us/dotnet/framework/data/wcf/service-operations-wcf-data-services
    [WebGet] // this attribute is required - ^see the link above^
    public IQueryable<Contragent> GetContragentsByIsContained(int isContained)
    {
        IQueryable<Contragent> result = entities.Contragent;
        List<string> neededNames = GetNeededNames();
        if (isContained == 0)
        {
            result = result.Where(x => !neededNames.Contains(x.Name));
        }
        else if (isContained == 1)
        {
            result = result.Where(x => neededNames.Contains(x.Name));
        }
        // else - no filtering

        return result;
    }
}
我的表中的一个部分显示此结果,但它不起作用

打开Fiddler看看发生了什么告诉我出了什么问题。我看到,SAP UI 5发送了以下请求:400 HTTP localhost:port/Services/MyService.svc/getContragentsBysContained和400 HTTP localhost:port/Services/MyService.svc/getContragentsBysContained?$skip=0和$top=25。我一点也不感到惊讶,服务器400对他们来说很重要,因为。。。嘿,SAP,isContained参数去哪了!? 这让我在Fiddler或浏览器中做了另一个测试-没关系:http://localhost:port/Services/MyService.svc/GetContragentsByIsContained?isContained=1&$filter=Name eq'Test123'。有一个名为Test123的反向代理,它是所需名称中的一个,因此isContained=1的查询按其应返回1项,而isContained=0的查询不返回任何项,这也是预期的结果。因此,UI5库将以$开头的特殊参数附加到URL的末尾,而不需要删除包含的参数,这应该不是问题

因此,最后一个问题是:SAP库在运行后删除所有内容是否正常?在加载数据之前是否在绑定路径中?如何保留此参数?提前谢谢

编辑:我忘了告诉你,我试图添加

urlParameters: {
    "isContained": (typeof (isContained) === 'string' && isContained !== '' ? isContained : 2 )
}
就像我想读的那样:

model.read("/GetContragentsByIsContained" {
    urlParameters: {
        "isContained": (typeof (isContained) === 'string' && isContained !== '' ? isContained : 2 )
    },
    success: function (count, args) {
        debugger;
        table.rows = count.results; // this doesn't work as well
    },
    error: function (args) {
        debugger;
        console.log(args);
    }
});

它不起作用。

下面,您可以在XML视图中找到声明性聚合绑定的有效synax:

items="{
    path: '/MySuperSet',
    parameters: {
        custom: {
            foo: 'bar'
        }
    }
}"

请注意,无法传递以$开头的自定义参数。上课见。

非常感谢!它很有魅力我不知道,这样的参数需要放在属性“custom”中,而属性“custom”位于绑定的属性“parameters”中。是的,看起来有点混乱,但实际上是这样的:
items="{
    path: '/MySuperSet',
    parameters: {
        custom: {
            foo: 'bar'
        }
    }
}"