fiori开发笔记

fiori开发笔记筛选数组new_data=results.filter(function(element,index){returnelement[‘GLAccount’]==”21190000″;});保留小数位.toFixed(2);去掉前导零s.replace(/\b(0+)/gi,””)当前日期varstrDate1=newDate().getFullYear()+”-“+((newDate().getMonth()+1)&l…

筛选数组

new_data = results.filter(function(element, index) {

return element[‘GLAccount’] ==”21190000″;

});

 

保留小数位

.toFixed(2);

 

去掉前导零

s.replace(/\b(0+)/gi,“”)

 

当前日期

var strDate1 = new Date().getFullYear() + “-” + ((new Date().getMonth() + 1) < 10 ? “0” : “”) + (new Date()

.getMonth() + 1) + “-” + (new Date().getDate() < 10 ? “0” : “”) + new Date().getDate();

 

引用外部js文件

https://blogs.sap.com/2017/04/30/how-to-include-third-party-libraries-modules-in-sapui5/

注:

1.对于xsjs,小写引入,使用XLSX,否则会提示undefined。原因是引用的 是xsjs的文件,传入参数随便取个名字,最终使用的是XLSX这个对象,所以传入参数不要和XLSX重名了

2.解决web ide语法检查报错:/* global XLSX:true */

 

debug

console.log()

 

router

带标识跳转

this.getRouter().navTo(“Detail”, {

id: “#”,

deal: “new”

});

 

字符串操作

查找是否包含字符串

if(email.indexOf(oSearchData.EmailAddress) != -1 ){} //包含

str.indexOf(“Hello”)

 

View操作

busy

this.getView().setBusy(true);

 

 

全局操作

sap.ui.getCore().Main = this;

 

布局

  1. 强制放在同一行,用HBOX
  2. 控件的水平间距

<Label text=”Hello” id=”txt11″ class=”sapUiSmallMarginEnd”/>

  1. 1
  2.  
  3. 1
  4.  

 

 

message

报错

MessageToast.show(JSON.parse(oError.responseText).error.message.value);

国际化message

MessageToast.show(that.getmessage(“savesuccess”));

 

取用户信息

需要先加入ushell,否则会报错,在fiori环境运行,单独运行也会报错

data-sap-ui-libs=”sap.m, sap.ui.layout, sap.ushell”

this._oUser = sap.ushell.Container.getUser();

 

 

组件

SimpleForm

layout=”ResponsiveGridLayout” 控制列自动调整适应行

columnsL 列数 L 表示 large 屏幕

labelSpanL label的长度

emptySpanXL 每一行结束的空单元格,可以导致换行

 

FilterBar

onClear: function (oEvent) {

var oFilterBar = this.byId(this.getView().getId() + “–filterbar”);

var oItems = oFilterBar.getAllFilterItems(true);

for (var i = 0; i < oItems.length; i++) {

var oControl = oFilterBar.determineControlByFilterItem(oItems[i]);

if (oControl) {

oControl.setValue(“”);

}

}

}

必填

<fb:FilterItem name=”A1″ label=”{i18n>CompanyCode}” mandatory=”true”>

 

下拉框

<Select width=”8rem” id=”Gender” forceSelection=”false” selectedKey=”{search>/JournalEntryType}”>

<core:Item key=”ZI” text=”Income”/>

<core:Item key=”ZE” text=”Excome”/>

</Select>

 

AJAX

如果sap cloud destination需要传自定义header,需要设置白名单

在 neo-app.json文件加

“headerWhiteList”: [“X-Custom1 “,” X-Custom2″]

 

https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/df89d9cd06a84905a3a4747f102c5b2c.html?q=header%20whitelist

 

fiori launch pad intent navigation

在 controller的init里,apptype 对应到 manifest的target

if (location.href.indexOf(“Zsalesreport-Display”) !== -1) {

window.location.replace(location.href.split(“Zsalesreport-Display”)[0] + ‘Zsalesreport-Display’ + ‘&/SalesReport’);

sap.ui.getCore().apptype = ‘SalesReport’;

}

 

Odata filter的格式

filterDateGet: function (Date) {

var strDate1 = Date.getFullYear() + “-” + ((Date.getMonth() + 1) < 10 ? “0” : “”) + (Date.getMonth() + 1) + “-” + (Date.getDate() <

10 ? “0” : “”) + Date.getDate();

strDate1 = “datetime'” + strDate1 + “T16:00:00′”;

return strDate1;

}

 

Model

创建odataModel

var oSalesPriceModel = new sap.ui.model.odata.ODataModel(“/s4cloud/sap/opu/odata/sap/API_SLSPRICINGCONDITIONRECORD_SRV/”, true);

注:/s4cloud 是web ide配置的app的path,path会和destination匹配,具体位置在这里。

(如果manifest配了datasource,会自动增加一行,如果没配也没手工改文件,会报404的)

fiori开发笔记

 

同步异步

OdataModel Version, earlier was using (sap.ui.model.odata.v2.ODataModel) so Async: false was not working,

by changing it to (sap.ui.model.odata.ODataModel) it is working fine.

new出来的可以同步

new sap.ui.model.odata.ODataModel(“/s4cloud/sap/opu/odata/sap/API_SLSPRICINGCONDITIONRECORD_SRV/”, true);

get的默认异步,要同步修改manifest的sap.ui.model.odata.v2.ODataModelsap.ui.model.odata.ODataModel即可

this.getView().getModel()

 

odata操作

删除

oProductModel.remove(sdealPath, {

async: false,

success: function (oData, response) {},

error: function (oError) {}

});

同步

model不能直接get

var oProductModel = new ODataModel(“/s4cloud/sap/opu/odata/sap/API_PRODUCT_SRV”, true);

{async: false,

success: function (oData, response) {},

error:function(oError){}

}

read filter

注:filter查不到不会进error 404

https://my300127-api.saps4hanacloud.cn/sap/opu/odata/sap/YY1_POS_USER_PARMETERS_CDS/YY1_POS_USER_PARMETERS?$filter=userid eq ‘DEFAULT_USER’

 

// define filters

var aFilters = [

new sap.ui.model.Filter(“userid”,

sap.ui.model.FilterOperator.EQ,””)

];

 

var sdealPath = “/YY1_POS_USER_PARMETERS”;

 

this.getView().setBusy(true);

this.getView().getModel(“odata_parameters”).read(sdealPath, {

async: false,

filters: aFilters,

success: function (oData, oResponse) {

},

error: function (error) {

}

});

 

filter 的 or条件

odata的read filter不能用or,binding的filter可以

odata的read要用or需要自己拼url

Request URL:

https://webidetesting1867853-caa613b5d.dispatcher.ap1.hana.ondemand.com/s4cloud/sap/opu/odata/sap/API_MATERIAL_DOCUMENT_SRV/A_MaterialDocumentItem?$filter=(MaterialDocumentYear%20eq%20%272019%27%20and%20MaterialDocument%20eq%20%274900000000%27)%20or%20(MaterialDocumentYear%20eq%20%272019%27%20and%20MaterialDocument%20eq%20%274900000001%27)

参考代码片段:

 

var that = this;

var oModel = new sap.ui.model.odata.ODataModel(“/s4cloud/sap/opu/odata/sap/API_PRODUCT_SRV/”, true);

var sdealPath = “/A_MaterialDocumentItem” + “?$filter=”;

for (var i = 0; i < results.length; i++) {

if (i > 0) {

sdealPath = sdealPath + ” or “;

}

sdealPath = sdealPath + “(Material eq ‘” + results[i].Material + “‘)”;

}

 

oModel.read(sdealPath, {

async: false,

success: function (oData, oResponse) {

debugger;

if (oData.results.length !== 0) {

 

} else {

MessageToast.show(“Product don’t exsit”);

}

},

error: function (error) {

debugger;

var msg = that.detailMessageGet(error);

MessageToast.show(“Product read error:” + msg);

}

});

 

filter 日期格式

and ConditionValidityStartDate le datetime’2019-09-23T16:00:00′ and ConditionValidityEndDate ge datetime’2019-12-29T16:00:00′

 

update(以修改批次特性为例)

var jsonData = {

“CharcValueDependency”: “1”,

“CharcValue”: “ZLAN_WPCB80001”,

“CharcFromNumericValue”: 0,

“CharcFromNumericValueUnit”: “”,

“CharcToNumericValue”: 0,

“CharcToNumericValueUnit”: “”,

“CharcFromDecimalValue”: “0”,

“CharcToDecimalValue”: “0”,

“CharcFromAmount”: “0”,

“CharcToAmount”: “0”,

“Currency”: “”,

“CharcFromDate”:null,

“CharcToDate”: null,

“CharcFromTime”:{ms: 0, __edmType: “Edm.Time”},

“CharcToTime”: {ms: 0, __edmType: “Edm.Time”},

“CharacteristicAuthor”: “”

};

var oModel = that.getView().getModel(“Batch”);

oModel.update(

// “/BatchCharcValue(Material=’ACA-00004′,BatchIdentifyingPlant =”,Batch=’9000003428′,CharcInternalID =’15’,CharcValuePositionNumber: ‘1’)”,

“/BatchCharcValue(Material=’ACA-00004′,BatchIdentifyingPlant=”,Batch=’9000003428′,CharcInternalID=’15’,CharcValuePositionNumber=’1′)”,

jsonData, {

success: function (oData, response) {

debugger;

},

error: function (oError) {

debugger;

}

});

 

create

var parData = this.getView().getModel(“parameters”).getData();

 

给model设置属性值

// var path = this.searchhelp.getBindingContext(‘bpbukrs’).getPath();

// this.getView().getModel(“bpbukrs”).setProperty(path + ‘/CompanyCode’,seldata.CompanyCode);

 

oData 问题

400:url不对,可能语法不对,或者有空格

428/412:为了确保update或者delete的数据是最新的,需要设置eTag:,值为read之后取到的metadata.eTag属性值(不是entity里的)

oSalesPriceModel.update(sdealPath, salesPrice, {

async: false,

// eTag: oData.results[0].ETag,

eTag: oData.results[0].__metadata.etag,

success: function (oData, response) {

debugger;

},

Invalid parametertype used at function ‘eq’ :可能参数值没有引号

 

 

今天的文章fiori开发笔记分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/11458.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注