gpt4 book ai didi

javascript - 我想将值传递给使用 odata 的标签

转载 作者:行者123 更新时间:2023-12-03 11:59:00 26 4
gpt4 key购买 nike

由于声明的变量(idno,namecity)位于括号内,我无法从外部访问它们。这是获得值(value)的方式还是最好的方式?谢谢您

<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 的示例,而不是与之对抗,不必进行显式读取,也不必访问结果 直接获取属性,而不是手动捕获检索到的数据并将其放入新的 JSON 模型中。

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

Here's the JS Bin example 。我用 XML 编写了 UI 控件,因为它更简洁,并使用了 Northwind 模型,但在其他方面尝试保持最初的目标。

以下是该示例的一些片段:

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

注意页面上的绑定(bind)以及标签文本属性中的绑定(bind)。

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() 调用,没有任何 try catch 和存储数据的回调成功处理程序,并且没有任何帮助程序JSON 模型。 (此外,我正在使用非常有用的 cors-anywhere 服务,因此我们可以查看远程 OData 服务的示例,而无需使用代理等)。

关于javascript - 我想将值传递给使用 odata 的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25486738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com