0

我正在 sencha touch 2.0 中创建一个应用程序

我正在使用导航视图

我创建了一个按升序排列的数字数学测验

我的问题是当我运行应用程序时它第一次工作正常但是当我点击后退按钮并且老化进入同一个视图时它向我显示旧号码

重要的是按钮文本上出现了新数字,但是当我单击按钮并获取文本时,它会显示旧数字

我的代码

sequence_user_answer="";
sequence_answer="";
sequence_number1=this.getRandomNumber(99,10);
sequence_number2=this.getRandomNumber(99,10);
sequence_number3=this.getRandomNumber(99,10);
       if(sequence_number1==sequence_number2)
       {
            while(sequence_number1==sequence_number2)
            {
                sequence_number2=this.getRandomNumber(99,10);
            }
       }
       else if(sequence_number3==sequence_number1 || sequence_number3==sequence_number1)
       {
            while(sequence_number3==sequence_number2 || sequence_number3==sequence_number1)
            {
                sequence_number3= this.getRandomNumber(99,10);
            }
       }


       var sequencenumber1=Ext.getCmp('NumberSequence1');
       sequencenumber1.setHtml(sequence_number1);

       var sequencenumber2=Ext.getCmp('NumberSequence2');
       sequencenumber2.setHtml(sequence_number2);
      // alert("two");

       var sequencenumber3=Ext.getCmp('NumberSequence3');
       sequencenumber3.setHtml(sequence_number3);

       var label1=Ext.getCmp('lblsequencenumber1');
       label1.setHtml("");

       var label2=Ext.getCmp('lblsequencenumber2');
       label2.setHtml("");

       var label3=Ext.getCmp('lblsequencenumber3');
       label3.setHtml("");

       if(sequence_number1>sequence_number2)
       {
            if(sequence_number1>sequence_number3)
            {

                if(sequence_number2>sequence_number3)
                {
                    sequence_answer=sequence_answer+sequence_number3;
                    sequence_answer=sequence_answer+sequence_number2;

                }
                else
                {
                    sequence_answer=sequence_answer+sequence_number2;
                    sequence_answer=sequence_answer+sequence_number3;

                }
                sequence_answer=sequence_answer+sequence_number1;
            }
            else
            {

                sequence_answer=sequence_answer+sequence_number2;
                sequence_answer=sequence_answer+sequence_number1;
                sequence_answer=sequence_answer+sequence_number3;
            }
       }
       else
       {
            if(sequence_number2>sequence_number3)
            {
                if(sequence_number1>sequence_number3)
                {
                    sequence_answer=sequence_answer+sequence_number3;
                    sequence_answer=sequence_answer+sequence_number1;
                }
                else
                {
                    sequence_answer=sequence_answer+sequence_number1;
                    sequence_answer=sequence_answer+sequence_number3;
                }
                sequence_answer=sequence_answer+sequence_number2;
            }
            else
            {
                sequence_answer=sequence_answer+sequence_number2;
                sequence_answer=sequence_answer+sequence_number1;
                sequence_answer=sequence_answer+sequence_number3;
            }
       }

在按钮点击

getSequenceAnswer:function(selected_button_id)
{
       //alert(selected_button_id);
       alert(selected_button_id.getHtml()); // here it shows me an old value when i go back and enter again to this view
       var ans_audio=Ext.getCmp('answeraudio');
       var que_audio=Ext.getCmp('questionaudio');
       var result=Ext.getCmp('statuslbl');
       if(sequence_count==0)
       {
            var sequence_label1=Ext.getCmp('lblsequencenumber1');
            sequence_label1.setHtml(selected_button_id.getHtml());
            sequence_count++;
            sequence_user_answer=sequence_user_answer+selected_button_id.getHtml();
       }
       else if(sequence_count==1)
       {
            var sequence_label2=Ext.getCmp('lblsequencenumber2');
            sequence_label2.setHtml(selected_button_id.getHtml());
            sequence_count++;
            sequence_user_answer=sequence_user_answer+selected_button_id.getHtml();
       }
       else if(sequence_count==2)
       {
            var sequence_label3=Ext.getCmp('lblsequencenumber3');
            sequence_label3.setHtml(selected_button_id.getHtml());
            sequence_count++;
            sequence_user_answer=sequence_user_answer+selected_button_id.getHtml();

            if(sequence_answer==sequence_user_answer)
            {
                que_audio.setUrl("");
                ans_audio.setUrl('audio/true.mp3');
                ans_audio.play();            
                this.getTrue(result);
                var marks=Ext.getCmp('lblMarks');
                sequence_marks = sequence_marks+2;
                marks.setHtml(sequence_marks);            
                var total=Ext.getCmp('lbltotal');
                sequence_total_marks= sequence_total_marks+2;
                total.setHtml(sequence_total_marks);
            }
            else
            {
                que_audio.setUrl("");
                ans_audio.setUrl('audio/false.mp3');
                ans_audio.play();
                this.getFalse(result);
                var total=Ext.getCmp('lbltotal');
                sequence_total_marks= sequence_total_marks+2;
                total.setHtml(sequence_total_marks);
            }
       }
}
4

1 回答 1

0

您很可能可以使用 show listener,它在容器显示时调用。在此处编写动态创建组件的逻辑。或者,作为另一种选择,您可以重置标签或其中的其他组件数据。

listeners: {
    show: function(list, opts){
        // code to reset  your comp
    }
}
于 2012-08-30T21:12:34.047 回答