基于Nano动态存储的Rubymotion查询
我在iOS应用程序中有一个方法,它查询数据库,然后将数据放入ruby循环中。我让循环动态地向ruby循环中添加一个数字,但它正在吸引所有用户基于Nano动态存储的Rubymotion查询,ruby,rubymotion,Ruby,Rubymotion,我在iOS应用程序中有一个方法,它查询数据库,然后将数据放入ruby循环中。我让循环动态地向ruby循环中添加一个数字,但它正在吸引所有用户 # Query all children in database child = Child.all # Loop through children and add count. count = child.count 0.upto(count - 1) do |c| p "#{@child.each do |child| child.first
# Query all children in database
child = Child.all
# Loop through children and add count.
count = child.count
0.upto(count - 1) do |c|
p "#{@child.each do |child| child.first_name end}" + "['#{c}']"
end
通过这组查询和循环,我得到了以下答案:
“[子项:0x8dee0,子项:0x8de2860]['0']”,
[子项:0x8dee0,子项:0x8de2860][1']
我不需要为每个数字提供相同的子项,而是需要它按如下方式查询答案:
“[子项:0x8dee0]['0']”,
“[子项:0x8de2860]['1']”
任何帮助都将不胜感激。谢谢。如果循环试图打印数组中子对象的名字, 试试这个:
0.upto(count - 1) do |c|
p child[c].first_name
end
或者,您可以完全跳过计数:
child.each do |achild|
p achild.first_name
end