【发布时间】:2019-10-04 06:14:13
【问题描述】:
基本上我有一个 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
我希望能够跟踪按下了哪个学生姓名,但我找不到这样做的方法。我需要这个,以便我可以在数据库中跟踪它的名称,以便显示他们的信息
【问题讨论】:
-
您可以使用
event.x和event.y来确定学生计数值,假设您的数据库的顺序与您进行显示时的顺序相同,您可以获得相同的行,使用一些东西像这样:stackoverflow.com/questions/16568/… -
我不需要知道学生的计数值,而是点击了哪些学生值,所以与数据库无关,而与变量无关
-
哦,要做到这一点,只需使用
self访问文本对象并获取设置为row.name的文本字段的值 -
local function studentscene(event) local name = event.target.text; ... end
标签: sql sqlite lua coronasdk scene