在SAPUI5中绑定OData

时间:2015-07-15 17:00:25

标签: odata sapui5

我是SAPUI5的新手。我正在增强我们的FIORI应用程序。我没有绑定数据的问题。

以下是我们的odata模型的console.log的结果

{"d":{"__metadata":{"id":"xxxxx/sap/opu/odata/sap/zlord_my_quotation_srv/QuotationSet('20000036')","uri":"xxxxx/sap/opu/odata/sap/zlord_my_quotation_srv/QuotationSet('20000036')","type":"zlord_my_quotation_srv.Quotation"},"Search":{"__metadata":{"type":"zlord_my_quotation_srv.Search"},"SearchTerm":""},"IcompletionStatus":"C","IcompletionStatusDesc":"Complete","NetValue":"0.00","Currency":"NOK","ValidTo":"/Date(1436486400000)/","ValidFrom":"/Date(1436486400000)/","Division":"10","DistributionChannel":"10","SalesOrganization":"1300","SoldToParty":"EKS","QuotationID":"20000036","RejectionStatus":"","ProcessingStatus":"","SoldToPartyDescription":"EKS / Royal 3310 / N-1234 Norway","CreatedOn":"/Date(1436486400000)/","SalesDocumentTypeDesc":"Quotation","RejectionStatusDesc":"not available","ProcessingStatusDesc":"New","ReferenceStatus":"","ReferenceStatusDesc":"not available","ItemIcompletionStatus":"","ItemIcompletionStatusDesc":"not available","PurchaseOrder":"","SalesDocumentTypeCode":"QT","SalesOrder":"1046","QuotationHeaderSet":{"__deferred":{"uri":"xxxxxx/sap/zlord_my_quotation_srv/QuotationSet('20000036')/QuotationHeaderSet"}}}}

基本上我只想将SalesOrder绑定到我的UI。

这是我们的view.xml

    <Label 
    id="salesOrderLabel"
    text="{i18n>Sales Order}" 
    visible="false"/> 
<Text 
    id="salesOrderText"
    value="{path:'SalesOrder'}"
    visible="false" />

<Label 
    id="triggerSalesOrderLabel"
    text="Trigger Sales Order"
    visible="false"/>
<Button 
    id="triggerSalesOrderButton"
    text="Create Sales Order" 
    icon="sap-icon://sales-order" 
    width ="200px" 
    visible="false" />

这是我们的控制器

    manageSalesOrderFields: function() {

    var salesOrderId = "";

    //hide all fields
    view.byId("salesOrderLabel").setVisible(false);
    view.byId("salesOrderText").setVisible(false);
    view.byId("triggerSalesOrderLabel").setVisible(false);
    view.byId("triggerSalesOrderButton").setVisible(false);

    //$.getJSON("/sap/opu/odata/sap/zlord_my_quotation_srv/QuotationHeaderSet('" + quotationId + "')", 
    $.getJSON("/sap/opu/odata/sap/zlord_my_quotation_srv/QuotationSet('" + quotationId + "')", 

    function(data) {





        //salesOrderId = data.d.SalesOrder;
        salesOrderId = data.d.SalesOrder;
        //console.log(data);
        alert("SO - " + salesOrderId);
        if (salesOrderId !== "" ){
            view.byId("salesOrderLabel").setVisible(true);
            view.byId("salesOrderText").setVisible(true);


        }else{
            view.byId("triggerSalesOrderLabel").setVisible(true);
            view.byId("triggerSalesOrderButton").setVisible(true);
            view.byId("triggerSalesOrderButton").detachPress(sap.ui.controller("cus.sd.myquotations.SD_MYQUOTESExtension_Michael2.view.S3Custom").createSalesOrder);
            view.byId("triggerSalesOrderButton").attachPress(sap.ui.controller("cus.sd.myquotations.SD_MYQUOTESExtension_Michael2.view.S3Custom").createSalesOrder);
        }

    var oModel1 = new sap.ui.model.json.JSONModel();
    // set the data for the model
    oModel1.setData(data);
    // set the model to the core
    //sap.ui.getCore().setModel(oModel1);
    console.log(oModel1.getJSON());

    var oSalesOrderText = view.byId("salesOrderText");
    oSalesOrderText.setModel(oModel1);

    oSalesOrderText.bindElement("value", "SalesOrder");




    });

    // create JSON model instance






},

没有错误,但我无法在我的UI中显示SalesOrder。有人能指出我正确的方向。

1 个答案:

答案 0 :(得分:3)

sap.m.Text没有名为value的属性。

将其替换为text属性。事情应该很好。

<Text 
    id="salesOrderText"
    text="{SalesOrder}"
    visible="false" />