在Rails的helper中,我建立这样一个方法:
def ul_li_ul_nest
fruit = %w(apple watermelon orange pear pineapple)
info = %w(price place weight)
content_tag(:ul) do
fruit.collect do |i|
content_tag(:li) do
i
content_tag :ul do
info.collect do |ii|
content_tag :li do
ii
end
end.join('').html_safe
end
end
end.join('').html_safe
end
end
它输出的结果是:
-
- price
- place
- weight
-
- price
- place
- weight
-
- price
- place
- weight
-
- price
- place
- weight
-
- price
- place
- weight
而我期望的输出结果是:
-
apple
- price
- place
- weight
-
watermelon
- price
- place
- weight
-
orange
- price
- place
- weight
-
pear
- price
- place
- weight
-
pineapple
- price
- place
- weight
如何修改才能达到这种结果?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
认证0级讲师