将数据绑定到表

时间:2017-01-21 13:10:02

标签: sapui5 sap-fiori

如何使用odata模型绑定数据?我收到的错误就像找不到资源“结果”一样。

我的代码:

wp_schedule_event( time(), 'hourly', 'price_from_mail_event' );
add_action( 'price_from_mail_event',  'update_price_from_mail' );
function update_price_from_mail(){
    $hostname = "{imap.gmail.com:993/imap/ssl}INBOX";
    $username = "xyzmail@gmail.com";
    $password = "password";
    $inbox = imap_open($hostname,$username,$password);
    if($inbox){
        $cement_emails = imap_search($inbox,'SUBJECT "Cement" UNSEEN'); // search unread mails with subject Cement
        $tmt_emails = imap_search($inbox,'SUBJECT "TMT" UNSEEN'); // search unread mails with subject TMT
        if($cement_emails){
            //process data and update price
        }
        if($tmt_emails){
            //process data and update price
        }
    }
}

3 个答案:

答案 0 :(得分:2)

  1. 您正在使用的ODataMOdel已弃用,请务必使用v2.ODataModel
  2. 您不需要通过JavaScript(ODataModel.read(...))执行HTTP调用来获取数据,以便将其绑定到表。
  3. 我认为你并没有清楚地了解UI5中的OData和模型。查看官方SAPUI5 Tutorials可能会帮助您。
  4. 无论如何,这是一个running jsbin example

    
    
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>SAPUI5 single file template | nabisoft</title>
            <script
            	src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
                id="sap-ui-bootstrap"
                data-sap-ui-theme="sap_bluecrystal"
                data-sap-ui-libs="sap.m"
                data-sap-ui-bindingSyntax="complex"
                data-sap-ui-compatVersion="edge"
                data-sap-ui-preload="async"></script>
                <!-- use "sync" or change the code below if you have issues -->
    
            <!-- XMLView -->
            <script id="myXmlView" type="ui5/xmlview">
                <mvc:View
                    controllerName="MyController"
                    xmlns="sap.m"
                    xmlns:core="sap.ui.core"
                    xmlns:mvc="sap.ui.core.mvc">
    
                    <Table
                        id="myTable"
                        growing="true"
                        growingThreshold="10"
                        growingScrollToLoad="true"
                        busyIndicatorDelay="0"
                        items="{/Customers('ALFKI')/Orders}">
                        <headerToolbar>
                            <Toolbar>
                                <Title text="Orders of ALFKI"/>
                                <ToolbarSpacer/>
                            </Toolbar>
                        </headerToolbar>
                        <columns>
                            <Column>
                                <Text text="OrderID"/>
                            </Column>
                            <Column>
                                <Text text="Order Date"/>
                            </Column>
                            <Column>
                                <Text text="To Name"/>
                            </Column>
                            <Column>
                                <Text text="Ship City"/>
                            </Column>
                        </columns>
                        <items>
                            <ColumnListItem type="Active">
                              <cells>
                                  <ObjectIdentifier title="{OrderID}"/>
    
                                  <Text
                                      text="{
                                          path:'OrderDate',
                                          type:'sap.ui.model.type.Date',
                                          formatOptions: {
                                            style: 'medium',
                                            strictParsing: true
                                          }
                                      }"/>
    
                                  <Text text="{ShipName}"/>
    
                                  <Text text="{ShipCity}"/>
    
                              </cells>
                            </ColumnListItem>
                        </items>
                    </Table>
    
                </mvc:View>
            </script>
    
            <script>
                sap.ui.getCore().attachInit(function () {
                    "use strict";
    
                    //### Controller ###
                    sap.ui.define([
                        "sap/ui/core/mvc/Controller",
                        "sap/ui/model/odata/v2/ODataModel"
                    ], function (Controller, ODataModel) {
                        "use strict";
    
                        return Controller.extend("MyController", {
                            onInit : function () {
                                // in component based apps you would not
                                // even need this piece of code:
                                this.getView().setModel(
                                    new ODataModel("https://cors-anywhere.herokuapp.com/services.odata.org/V2/Northwind/Northwind.svc/", {
                                        json : true,
                                        useBatch : false
                                    })
                                );
                            }
                        });
                    });
    
                    //### THE APP: place the XMLView somewhere into DOM ###
                    sap.ui.xmlview({
                        viewContent : jQuery("#myXmlView").html()
                    }).placeAt("content");
    
                });
            </script>
    
        </head>
    
        <body class="sapUiBody">
            <div id="content"></div>
        </body>
    </html>
    &#13;
    &#13;
    &#13;

答案 1 :(得分:0)

尝试更改

that.getView()则setModel(oModel,&#34;学生&#34);

:此 .getView()则setModel(oModel,&#34;学生&#34);

答案 2 :(得分:0)

that.getView()则setModel(oModel, “学生”)。 //不正确

this.getView()则setModel(oModel, “学生”)。 //指的是这个特定的控制器