[英]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.