我的SAPUI5应用程序具有条形码扫描功能。首先,用户将看到一个弹出窗口,可以在其中进行条形码扫描;如果扫描的条形码正确,它将触发“下一步”按钮,并依次显示另一个弹出窗口,用于下一次条形码扫描。对于第一个条形码,用户必须扫描6-7位数字,而在第二个条形码上,用户应扫描5位数字。我的问题是第一条条形码的自动触发。当用户扫描7位数字时,它将触发下一个2x。有没有办法知道扫描的条形码文本的最后长度?
这是我的TextInput liveChange事件
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时再次触发。
新密码
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);
}
},
用作蓝牙键盘的条形码扫描仪将非常快速地“键入”其数据。如果您收到了6位数字,但可能在250毫秒之内未收到任何信息,则可以认为条形码已完成,并跳至下一页。
如果您收到的7位数字,您甚至不需要再等待,而是可以立即跳到下一页。
因此,我想您的代码必须看起来像这样:
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,输出
这将发生:
因此,如果接收到7个字符的条形码,则将同时执行char 6和char 7的逻辑,但是由于取消了char 6的计时操作,因此gotoNextPage方法仅启动一次。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句