视图加载后触发 BarcodeScannerButton

编程入门 行业动态 更新时间:2024-10-03 23:24:06
本文介绍了视图加载后触发 BarcodeScannerButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在我的 Fiori/UI5 应用程序上实现了一个扫描仪按钮.我使用了 sap.ndc.BarcodeScannerButton 并在控制器上创建了该按钮(我似乎无法在我的 view.xml 上创建该按钮).

I have implemented a scanner button on my Fiori/UI5 application. I used sap.ndc.BarcodeScannerButton and created that button on the controller (I cannot seem to create the button on my view.xml).

无论如何,我需要在视图加载后触发这个按钮.我有一个主从应用程序.扫描仪按钮在主视图上.

Anyway, I need to fire this button after the view loads. I have a master-detail application. The scanner button is on the master view ofcourse.

我做的第一件事就是调用按钮本身.但我的第一个问题是按钮不接受 id 作为参数.它告诉我应用程序不能接受重复的 ID.所以我所做的只是寻找按钮 id.我能够找到它(例如 _button9),但是每当我通过 sap.ui.getCore.byId() 调用它时,它有时会返回未定义".这就是为什么我不能调用 firePress();

First thing I did was call the button itself. But my first problem is that the button does not accept an id as a parameter. It tells me that app cannot accept duplicate id. So what I did was just look for the button id. I was able to locate it (e.g. _button9) but whenever I call it via sap.ui.getCore.byId() there are times that it returns "undefined." That's why I cannot call firePress();

我遇到的另一个问题是把这个 firePress() 方法放在哪里.我试图将它放在方法 onAfterRendering() 上,假设再次由于未定义的按钮我无法调用方法 firePress().我尝试将它放在其他方法上,例如在使用方法 attachRequestCompleted 成功调用数据之后.没有运气.

Another problem I have is where to put this firePress() method. I tried to put it on method onAfterRendering() assuming that again due to the undefined button I cannot call the method firePress(). I have tried putting it on other methods like after the data has been successfully called by using method attachRequestCompleted. No luck.

下面是代码

/* * Copyright (C) 2009-2014 SAP SE or an SAP affiliate company. All rights reserved */ jQuery.sap.require("sap.ca.scfld.md.controller.ScfldMasterController"); jQuery.sap.require("ui.s2p.srm.sc.create.util.Formatter"); jQuery.sap.require("sap.ndc.BarcodeScannerButton"); var counter = 0; sap.ui.controller("ui.s2p.srm.sc.create.SRM_SC_CREExtension.view.S2Custom", { onInit: function() { sap.ca.scfld.md.controller.ScfldMasterController.prototype.onInit.call(this); this.oBundle = this.oApplicationFacade.getResourceBundle(); this.isRoot = true; this.oRouter.attachRouteMatched(function(e) { if (e.getParameter("name") === "master" && !this.isRoot && Object.keys(e.getParameter("arguments")).length === 0) { var d = sap.ui.core.routing.History.getInstance().getDirection("shoppingCartCheckout/" + this.tempCartId); if (d === "Unknown") { this.isRoot = true; this._oControlStore.oMasterSearchField.clear() } else { if (this.getList() !== null) { var i = this.getList().getSelectedItem(); if (i !== null) { //alert("setListGo"); this.setListItem(i); } } } } this.isRoot = (this.isRoot) ? false : this.isRoot; }, this); // alert(sap.ui.getCore().byId("productScanButton")); this.onBarcodeScanning(); this.setEmptyCart(true); this.showAllProducts(); //added by salduam to show all products }, backToList: function() { //alert("back"); }, getDefaultUserSettings: function(r) { var o = function(D, R) { this.tempCartId = D.results[0].TEMP_CART_ID; if (!jQuery.device.is.phone) { if (r) { this.oRouter.navTo("noData", { viewTitle: "DETAIL_TITLE", languageKey: "NO_ITEMS_AVAILABLE" }, true) } else { this.navToEmptyView() } } }; var d = this.oApplicationFacade.getODataModel("getdefusrset"); d.read("DefaultUserSettings?ts=" + Date.now(), null, null, true, jQuery.proxy(o, this), jQuery.proxy(this.onRequestFailed, this)) }, applySearchPatternToListItem: function(i, f) { if (f.substring(0, 1) === "#") { var t = f.substr(1); var d = i.getBindingContext().getProperty("Name").toLowerCase(); return d.indexOf(t) === 0 } else { return sap.ca.scfld.md.controller.ScfldMasterController.prototype.applySearchPatternToListItem.call(null, i, f) } }, getHeaderFooterOptions: function() { var o = { sI18NMasterTitle: "MASTER_TITLE", buttonList: [] }; return o }, isBackendSearch: function() { return true }, //call startReadListData with parameter wildcard showAllProducts: function(e) { var startSearchText = "*"; this.startReadListData(startSearchText); //alert("called"); }, applyBackendSearchPattern: function(f, b) { //added by salduam //if search field is blank, automatically call showAllProducts if (f == "") { this.showAllProducts() }; if (f != "" && f != null) { this.startReadListData(f) } else { this.setEmptyCart(false) } }, startReadListData: function(f) { var o = function(D, r) { var m = new sap.ui.model.json.JSONModel(D.results); this.getView().setModel(m); this.getList().destroyItems(); this.getList().bindAggregation("items", { path: "/", template: this.oTemplate.clone(), filter: [], sorter: null }); this.registerMasterListBind(this.getList()); }; var e = encodeURIComponent(f); //console.log("EEEE-----"+ e); var d = this.oApplicationFacade.getODataModel(); //console.log(d); d.read("CATALOG_ITEM?$filter=startswith(description,'" + e + "')&$top=20", null, null, true, jQuery.proxy(o, this), jQuery.proxy(this.onRequestFailed, this)); }, setListItem: function(i) { // alert("onClick"); var b = i.getBindingContext(); var m = b.oModel.oData[parseInt(b.sPath.split('/')[1])]; this.oRouter.navTo("detail", { tempCartId: this.tempCartId, contextPath: b.getPath().substr(1) }, true); var c = sap.ui.core.Component.getOwnerIdFor(this.oView); var C = sap.uiponent(c); C.oEventBus.publish("ui.s2p.srm.sc.create", "refreshDetail", { data: m }); }, setEmptyCart: function(r) { var e = new sap.ui.model.json.JSONModel({ results: [] }); this.oRouter.navTo("noData", { viewTitle: "DETAIL_TITLE", languageKey: "NO_ITEMS_AVAILABLE" }, true); this.getView().setModel(e); this.oTemplate = new sap.m.ObjectListItem({ type: "{device>/listItemType}", title: "{matnr}", press: jQuery.proxy(this._handleItemPress, this), number: "{parts:[{path:'itm_price'},{path:'itm_currency'}],formatter:'ui.s2p.srm.sc.create.util.Formatter.formatPrice'}", numberUnit: "{itm_currency}", attributes: [new sap.m.ObjectAttribute({ text: "{description}" })], }); this.getList().bindAggregation("items", { path: "/results", template: this.oTemplate, filter: [], sorter: null, }); this.registerMasterListBind(this.getList()); this.getDefaultUserSettings(r) }, onRequestFailed: function(e) { jQuery.sap.require("sap.ca.ui.message.message"); sap.ca.ui.message.showMessageBox({ type: sap.ca.ui.message.Type.ERROR, message: e.message, details: e.response.body }) }, onExit: function() {}, onBarcodeScanning: function(oEvent) { var productScanButton = new sap.ndc.BarcodeScannerButton({ provideFallback: "{/btnFallback}", width: "100%", scanSuccess: function(oEvent) { var barcodeID = oEvent.getParameter("text"); sap.m.MessageToast.show(barcodeID); var searchField = sap.ui.getCore().byId("__field3"); searchField.setValue(barcodeID); searchField.fireSearch(); } }); this.getView().byId("barCodeVBox").addItem(productScanButton); }, onAfterRendering: function(oEvent) {}, onBeforeRendering: function() {} });

推荐答案

用于放置 fire() 方法.您是否要显示弹出式条码阅读器?类似于应用程序SD_SO_CRE"的弹出窗口(在主视图之前加载客户选择对话框).他们没有用 fire() 解决任务...

For placing the fire() method. Are you trying to display a pop-up barcode reader? something similar to the pop-up of the app "SD_SO_CRE" (where customer selection dialog is load before master view). they do not solve the task with fire()...

更多推荐

视图加载后触发 BarcodeScannerButton

本文发布于:2023-11-26 23:18:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635617.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   加载   BarcodeScannerButton

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!