简体   繁体   English

数组未正确返回(钛)

[英]Array not returned properly(Titanium)

I am returning the array using a function in titanium.There are two entries in my array which are showing alert but when i access the returned value in another js file.It only show one value in alert Here is my code (it is in db.js): 我使用钛函数返回数组。数组中有两个条目显示警报,但是当我访问另一个js文件中的返回值时,它仅在警报中显示一个值这是我的代码(在db中.js):

function quizfun() {
    var dataArray=new Array();
    var quizes = db.execute('select * from Quiz');
    while (quizes.isValidRow()) {
        var counter = 0;
        dataArray[counter] = quizes.fieldByName('Quiz_Text');
        quizes.next();
        alert(dataArray[counter]);//Showing two values
        counter++;
    };
    return dataArray;
}

Here is my other js file: 这是我的其他js文件:

  quizes = db.quizfun();
  alert(quizes[0]);//working
  alert(quizes[1]);//alert not showing anything

Could you tell me what i am doing wrong.Thanks in advance 你能告诉我我在做什么错。

var counter = 0; should be outside the while loop. 应该在while循环之外。 Like 喜欢

function quizfun() {
    var dataArray=new Array();
    var quizes = db.execute('select * from Quiz');
    var counter = 0;
    while (quizes.isValidRow()) {
        dataArray[counter] = quizes.fieldByName('Quiz_Text');
        quizes.next();
        alert(dataArray[counter]);//Showing two values
        counter++;
    };
    return dataArray;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM