如何在对话框SAPUI5中设置OData绑定的路径

时间:2019-02-12 07:34:28

标签: data-binding odata sapui5

我尝试将数据绑定到对话框中显示的列表视图中。 对话框通过主明细视图模板的明细视图中的onClick方法打开。

    onInit : function () {
            // Model used to manipulate control states. The chosen values make sure,
            // detail page is busy indication immediately so there is no break in
            // between the busy indication for loading the view's meta data
            var oViewModel = new JSONModel({
                busy : false,
                delay : 0,
                lineItemListTitle : this.getResourceBundle().getText("detailLineItemTableHeading")
            });

            this.getRouter().getRoute("object").attachPatternMatched(this._onObjectMatched, this);

            this.setModel(oViewModel, "detailView");

            this.getOwnerComponent().getModel().metadataLoaded().then(this._onMetadataLoaded.bind(this));


        },
    onNodeLeaveSent : function (){
            var dialog = new sap.m.Dialog({
            title: 'Invoce Documents',
            type: 'Message',
                content: new sap.m.List({
                    items:{
                        path: "{detailView>/PurchaseOrderDeliverySet}",
                        template: new sap.m.StandardListItem({
                            title: "{detailView>DNumber}",

                        })
                    }
                }),
            beginButton: new sap.m.Button({
                text: 'OK',
                press: function () {
                    dialog.close();
                }
            }),
            afterClose: function() {
                dialog.destroy();
            }
        });
        this.getView().addDependent(dialog);
        dialog.open();
        }

该列表未显示任何数据。我不理解如何正确地从数据模型中引用我的实体。

有人可以帮忙吗?

服务看起来像这样enter image description here

这是图元文件:

enter image description here

2 个答案:

答案 0 :(得分:0)

评论变得混乱,所以我将其写为答案:

您的初始编码应在项目中使用绝对绑定(前导/)。参见SAP Coding Example

path: "/PurchaseOrderDeliverySet"
  • 如果您的服务通过原始odata网址在浏览器中返回数据
  • 如果您的OData模型是不带名称的默认模型(在manifest.json中查找)

但是查看您的业务逻辑,您可能希望显示所选(在主视图中)和显示(在详细视图中)采购订单的所有交货。

DetailView中的元素绑定:/PurchaseOrder('1234')

因此,您想将PurchaseOrder实体的Navigation属性绑定到PurchaseOrderDelivery实体。关联在元数据中可见,而导航属性则不可见。我假设它存在,并在这里命名为POtoPODeliveries

在OData /PurchaseOrder('1234')/POtoPODeliveries中,为此特定PurchaseOrder 1234(如果正确实现)返回一个数组PurchaseOrderDeliverSet。

item属性的路径现在需要相对于DetailView现有元素绑定的相对绑定

path: "POtoPODeliveries"

template属性中的绑定始终与项目绑定相关,并且仅在项目绑定具有模型名称时才需要模型名称。

答案 1 :(得分:0)

我认为,以某种方式在视图的“子级”(在您的示例中为对话框)中无法访问在OnInit(在您的示例中为oViewModel)上创建的模型。

尝试这些>

  • 在manifest.json上声明您的模型,以便sapui5自动实例化它。这样,您可以尝试在应用程序的任何位置访问它:

    enter image description here

enter image description here