sql - 如何获取在 for 循环中创建的变量名
问题描述
基本上我有一个 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 函数中使用参数来添加它
`options = {
effect = model,
time = time,
params = params,
}
composer.gotoScene( nextScene , options )`
例如,这样做 params ={student="mohsen"}
并在场景:显示功能中这样做:
if event.params then
studen = event.params.name
end
推荐阅读
- symfony - Symfony 3.4 - 使用数组作为输入字段的名称
- excel - PlotBy 指令不适用于 xlColumnStacked100 图表
- apache-spark - 三角洲湖中使用的 spark.databricks.delta.snapshotPartitions 配置是什么?
- react-native - SwitchNavigator 中的屏幕 导航时闪烁
- json - 无法将json文件导入spyder
- sql - SQL出现字符替换问题
- python - 使用 sklearn 在 python 中查找 2D 转换以合并/拼接 2 个数据集(元组)重叠
- python - 在 for 循环中将几个值为“None”的变量更改为“n/a”
- csv - 用于登录、检索 cookie 并将 csv 转换为工作表的 Google 脚本
- unix - FreeBSD - tcpdump - 过滤某些 udp 端口