0

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

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

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

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

下面是代码

/*
 * 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.ui.component(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() {}

});
4

1 回答 1

0

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

于 2016-01-12T12:43:11.300 回答