首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >条形码扫描AutoTrigger上的LiveChange事件

条形码扫描AutoTrigger上的LiveChange事件
EN

Stack Overflow用户
提问于 2016-06-21 13:39:32
回答 2查看 1.8K关注 0票数 0

我的SAPUI5应用程序有条形码扫描功能。首先,用户将看到一个弹出,他可以在其中进行条形码扫描,如果扫描的条形码是正确的,它将触发下一个按钮,然后将显示另一个弹出,为下一个条码扫描。对于第一个条形码,用户必须扫描6-7位数字,而在第二个条形码上,应该是5位。我的问题是第一个条形码的自动触发器。当用户扫描7位数字时,它会触发下一个2x。有没有办法知道扫描条形码文本的最后长度?

这是我的liveChange TextInput事件

代码语言:javascript
复制
                        liveChange: function(oEvent) {

                        sText = oEvent.getParameter('value');
                        parent1 = oEvent.getSource().getParent();

                            if ((typeof sText != 'undefined') && (sText.length >= 6) )
                            {

                                sap.ui.getCore().byId(t.createId("costCenterInput")).setValue(sText);
                                setTimeout(function() { 
                                    console.log(parent1.getBeginButton());
                                    if (parent1.getBeginButton() != null){
                                    parent1.getBeginButton().firePress(oEvent); 
                                    }

                                    }, 5000);

                            }
                    }

这个代码的问题是外部条形码扫描器充当蓝牙键盘,一次输入一个数据。所以假设我们扫描1234567,在进入6的时候它就已经触发了,甚至在超时的时候也会触发,在进入7的时候会再次触发。

新码

代码语言:javascript
复制
    onScanAddressMobile: function(){

    var t = this;
    t.oBundle = this.oApplicationFacade.getResourceBundle();
    var dialog = new sap.m.Dialog(t.createId("ccDialog"), {
            title: t.oBundle.getText("COST_CENTER"),
            type: 'Message',
            content: [
                new sap.m.Text({ text: t.oBundle.getText("SCAN_COST_CENTER")}),
                new sap.m.Input(t.createId("costCenterInput"), {
                    type: "Number",
                    liveChange: 

                    function(oEvent){
                        t.onLiveChange(oEvent);
                    }

                }),
      .....some more code here...
      },

      onLiveChange : function(event) {
        //alert("onLiveChange");
                    var value = event.getParameter("value");
                    if (value && value.length === 6) {
                        alert("6 character");
                        this.timer = setTimeout(this.gotoNextPage(value), 4000);  
                    } else if (value && value.length > 6) {
                        alert("6 or more");
                        if (this.timer) {
                          clearTimeout(this.timer);
                        }
                        this.gotoNextPage(value);
                    }
    },
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-21 14:26:00

作为蓝牙键盘的条形码扫描器将非常快地“输入”其数据。如果您已经收到6位数字,然后没有收到任何可能250‘t,您可以考虑条形码完成,并跳到下一页。

如果您已经收到7位数字,您甚至不需要再等待,但可以立即跳到下一页。

所以我想你的代码应该是这样的:

代码语言:javascript
复制
onLiveChange : function(event) {
    var value = event.getParameter("value");
    if (value && value.length === 6) {
        this.timer = setTimeout(this.gotoNextPage, 250)  
    } else if (value && value.length > 6) {
        if (this.timer) {
          clearTimeout(this.timer);
        }
        this.gotoNextPage();
    }
}

请在jsbin:http://jsbin.com/kolacez/1/edit?html,output中找到一个超时时间稍长的示例。

这就是将要发生的事情:

  • 第1章:无
  • 第2章:无
  • 第3章:无
  • 第4章:无
  • 第5章:无
  • 第6章:定时器被设置,如果在一定的时间范围内没有接收到字符7,条形码被假定是完整的,它将启动gotoNextPage。
  • 第7章:计时器被取消,gotoNextPage直接启动。

因此,如果接收到7个字符的条形码,则会执行char 6和char 7的逻辑,但是由于char 6的计时器操作被取消,所以只启动一次gotoNextPage方法。

票数 0
EN

Stack Overflow用户

发布于 2016-06-22 13:13:39

通常,条形码扫描器可以配置为在扫描字符(或任何其他字符)的末尾发送一个“返回”值,但Chr(13)是最常见的,因为它可以在将表单插入输入字段时立即提交表单。

看看是否可以配置您的字符,只需检查最后一个字符(返回)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37946077

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档