[英]How to get a variable name that is created in a for loop
基本上,我有一个for循环,该循环基于数据库中的数据创建变量,然后有一个事件监听器,该事件监听器也基于for循环创建,我想知道按下了哪个文本
我已经尝试了函数中的事件,为我的row.name等创建了一个变量。
for row in db:nrows( "SELECT * FROM Students WHERE Class = '"..class.."'" ) do
print(row.Name)
--track how many students there are
count = count+1
--When displaying the names, put them in line, if they go below 1000 y level, move to the right and go down again
ny = ny + 80
if (ny == 1000) then
nx = nx + 300
ny = 280
end
-- Display students
student[row] = display.newText( sceneGroup, row.Name, nx, ny, native.systemFont, 30 )
--Make a button for every student in the row that goes to studentscene function
student[row]:addEventListener( "tap", studentscene)
end
该函数然后看起来像
local function studentscene()
composer.gotoScene( "student", { time=800, effect="crossFade" } )
end
我希望能够跟踪按下了哪个学生姓名,但我找不到解决方法。 我需要这个,所以我可以在数据库中跟踪它的名字,以便显示他们的信息
您可以通过在goto函数中使用params添加它
`options = {
effect = model,
time = time,
params = params,
}
composer.gotoScene( nextScene , options )`
例如,执行此params = {student="mohsen"}
并在scene:show函数中执行以下操作:
if event.params then
studen = event.params.name
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.