如何获得在for循环中创建的变量名

基本上我有一个for循环,根据数据库中的数据创建变量,然后我还有一个基于for循环创建的事件侦听器,并且我想知道哪个文本被按下。

我尝试了在函数中使用事件,为我的row.name创建变量等等。

for row in db:nrows( "SELECT * FROM Students WHERE Class = '"..class.."'" ) do
        print(row.Name)
        --跟踪学生人数
        count = count+1
        --当显示姓名时,将它们放在同一行,如果它们的y值低于1000,则向右移动并向下移动
        ny = ny + 80
        if (ny == 1000) then
            nx = nx + 300
            ny = 280
        end
        -- 显示学生
        student[row] = display.newText( sceneGroup, row.Name, nx, ny, native.systemFont, 30 )
        --为行中的每个学生创建一个按钮,该按钮进入studentscene函数
        student[row]:addEventListener( "tap", studentscene)
    end

函数现在看起来像这样

local function studentscene()
    composer.gotoScene( "student", { time=800, effect="crossFade" } )
end

我想知道哪个学生名字被按下,但是我找不到这样的方法。我需要这样做,以便我可以跟踪在数据库中是哪个名字,以便我可以显示他们的信息。

点赞
用户6831295
用户6831295

你可以通过在goto函数中使用params参数来添加它。

    `options = {
       effect = model,
       time = time,
       params = params,
    }
composer.gotoScene( nextScene , options )`

例如,在params中这样写:params = {student="mohsen"}, 然后在scene:show函数中,这样写:

if event.params then

studen = event.params.name
end
2019-07-26 18:40:36