@tree_ares = []
@areas.each do |e|
@tree_ares << {:id => e.id, :name => e.text, :parent_id => 1}
end
[ {:id=>1, :name=>"所有区县", :parent_id=>0}, {:id=>294, :name=>"长宁", :parent_id=>1}, {:id=>306, :name=>"闵行区", :parent_id=>1}, ] ztree 符合的数据结构:
zTreeNodes = [
{"name":"区县", open:true, children: [
{ "id":"1", "name":"闵行区", "parent_id":"1"},
{ "id":"2", "name":"宝山区", "parent_id":"1"},
{ "id":"3", "name":"卢湾区", "parent_id":"1"}
]
}
];
不知道怎么转换数据形式?