0

使用 Sencha Touch 2 的 Android 应用程序的按钮单击在 Android 2.3 模拟器中工作正常,但在 Android 3.0 及更高版本中无法正常工作。当我在 Android 3.0 及更高版本中运行此应用程序并单击保存按钮时,它不会从 var isValid 编译=真;线。我的代码如下: -

{
            xtype: 'button',
            text: 'Save',
         handler: function(){
         //var val3 = Ext.ComponentQuery.query('#na')[0].getValue(); 
         val3 = Ext.getCmp('na').getValue();
         console.log(val3);
         val = Ext.getCmp('ea').getValue();          
         console.log(val);
         val4 = val.indexOf("@");
         console.log(val4);
         val5 = val.lastIndexOf(".");
         console.log(val5);
         val2 = Ext.getCmp('pa').getValue();
         console.log(val2); 
         val1 = Ext.getCmp('ra').getValue();    
         console.log(val1); 
            var isValid = true;
            Ext.Msg.alert("Info", "123");
            var errors = new Array();
            Ext.Msg.alert("Info", "456");
           //validate the name                        
            if (val3.search(/[0-9]/) > -1) {
            Ext.Msg.alert("Info", "789");
              isValid = false;
              errors.push({field : 'name',
              reason : 'Name must not contain numbers'});
                }
             if (val3.length <= 0) {

              isValid = false;
              errors.push({field : 'name',
              reason : 'Name should not be blank'});
                }

                if (val3.search(/[@]/) > -1) {
              isValid = false;
              errors.push({field : 'name',
              reason : 'Name must not contain special characters'});
                }
             //validate e-mail                        
              if (val4<1 || val5<val4+2 || val5+2>=val.length)
             {
             isValid = false;
                errors.push({field : 'email',
                reason : 'Invalid email id'});
             }
            if (val.search("/^([a-zA-Z0-9_\.\-])+(@[a-z])+([.][a-z])+$+") > -1){
                isValid = false;
                errors.push({field : 'email',
                reason : 'Invalid Email address'});
              }
            if (val.length <= 0){
                isValid = false;
                errors.push({field : 'email',
                reason : 'Email address should not be blank'});
              }                   
            //validate Password                        
            if (val1 != val2) {
                isValid = false;
                errors.push({field : 'reenter',
                reason : 'Password do not match'});
                 } 
            if(val2 <= 0){
               isValid = false;
               errors.push({field : 'password',
               reason : 'Password should not be blank'});
                 }  
            if(val1 <= 0){
               isValid = false;
               errors.push({field : 'reenter',
               reason : 'Re-enter Password should not be blank'});
                 }  
            if(val1.length > 4){
               isValid = false;
               errors.push({field : 'reenter',
               reason : 'Re-enter Password should not be more than 4 characters'});
               }  
            if(val2.length > 4){
               isValid = false;
               errors.push({field : 'password',
               reason : 'Password should not be more than 4 characters'});
              }  
            //show error if the validation failed                        
            if (!isValid) {
               var errStr = "";
               Ext.each(errors, function(error, index){
               errStr += "[" + (index+1) + "] - " + error.reason + "\n";
               });
               Ext.Msg.alert("Error", errStr);
              } else {//form is valid
                //form.submit();
                Ext.Msg.alert("Info", "Success");
               }
             }
4

1 回答 1

0

我不想成为向你爆料的人,但 Sencha Touch 2 不支持 Android 3.x。只有 2.x 和 4.x。可以在这里找到一个快速的论坛讨论:

http://www.sencha.com/forum/showthread.php?186178-Phonegap-1.5-Sencha-Touch-2-has-problems-on-android-3.0

不过,您的语法看起来不错。

于 2012-07-19T21:08:26.707 回答