我想将值传递给消耗标签的odata [英] I want to pass the values to label consuming odata

查看:80
本文介绍了我想将值传递给消耗标签的odata的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为声明的变量(idno,namecity)在括号内,所以我无法从外部访问它们.这是获取价值的方法还是最好的方法.谢谢

since the variables declared(idno, namecity) are inside parentheses I could not access them out side. Is this the way to get values or which would be the best way. Thank You

<script>
    var app = sap.m.App("myApp",{});
    var url = "proxy/http/server/ZCUST_TESTING_SRV /?$filter=IKunnr eq '800COL101'";
    var username = "mobtest";
    var password = "welcome1";
    var oModel = new sap.ui.model.odata.ODataModel(url, true, username, password);  
    oModel.read('/', null, null, true, function(oData, oResponse)
    {
            var dataget = JSON.stringify(oData);        
            var count = oData.results[0].Ort01;
            var namecity= oData.results[0].Name1;
            var idno= oData.results[0].Kunnr;   
    });                 
    var l4 = new sap.m.Label("l4",{text: count});
    var l5 = new sap.m.Label("l5",{text: namecity});
    var l6 = new sap.m.Label("l6",{text: idno});        

    var page = new sap.m.Page("page",{
                title:"Address Details",
                showNavButton:true,
                navButtonTap: function(){
                    //app.back();
                    app.to("Page");
                },
                content: [ l4,l5,l6, new sap.m.Button({text:"submit" }})]
    });
    app.addPage(page);
    app.placeAt('content');
</script>

推荐答案

基于对您的问题的评论中的讨论,我为您整理了一个示例,该示例更恰当地使用ODataModel,而不是与之抗争,而不必执行显式读取,不直接访问results属性,不手动捕获检索到的数据并将其放入新的JSON模型中.

Based on the discussion in the comments to your question, I put together for you an example of using the ODataModel more appropriately, not fighting against it, not having to do explicit reads, not accessing the results property directly, and not capturing the retrieved data manually and putting it into a new JSON model.

基本上,实例化ODataModel,在控件属性上使用绑定语法,并设置适当的绑定上下文,以便解析相对路径.

Basically, instantiate the ODataModel, use binding syntax on your control properties, and set the appropriate binding context so that the relative paths resolve.

这是JS Bin示例.我使用XML编写了UI控件,因为它更加简洁,并使用了Northwind模型,但在其他方面尝试保持原始目标.

Here's the JS Bin example. I wrote the UI controls in XML as it's cleaner, and used the Northwind model, but otherwise tried to keep to your original goals.

以下是该示例的摘要:

  <App>
    <Page
      binding="{/Employees(1)}"
      title="Address Details"
      showNavButton="true">
      <content>
        <Label text="{TitleOfCourtesy}" />
        <Label text="{FirstName}" />
        <Label text="{LastName}" />
      </content>
    </Page>
  </App>

请注意页面上的绑定,以及标签文本属性中的绑定.

Note the binding on the Page, and the binding in the Label text properties.

oView
  .setModel(new sap.ui.model.odata.ODataModel(
        "http://cors-anywhere.herokuapp.com/http://services.odata.org/V3/Northwind/Northwind.svc/",
        {
          json : true,
          maxDataServiceVersion : "2.0"
        }
      ))

请注意ODataModel的设置方式,并注意不存在任何read()调用,不存在试图捕获和存储数据的任何回调成功处理程序,以及不存在任何辅助JSON模型. (此外,我正在使用非常有用的 cors-anywhere 服务,因此我们可以看一个示例远程OData服务,而无需使用代理等).

Note the way the ODataModel is set, and note the absence of any read() calls, the absence of any callback success handlers trying to catch and store the data, and the absence of any helper JSON models. (Also, I'm using the very useful cors-anywhere service so we can look at an example of a remote OData service without using proxies etc).

这篇关于我想将值传递给消耗标签的odata的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆