向高手求救-迭代生成树,急!!!

Raulgodle 2004-12-22 03:38:43
有如下表结构 id,name,parentid, 如何迭代生成树?
...全文
133 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangning163 2004-12-23
  • 打赏
  • 举报
回复
楼上介绍了树的生成!
你可以先DISTINCT parentid 生成树的第一级!
然后循环加载每个 parentid 对应的 l_tvi.data = id l_tvi.label = name 就 OK 啦!
wu_07 2004-12-23
  • 打赏
  • 举报
回复
仅供参考:

---------------------------------------------------
ids_cata用parentid排序先
wf_buildTree()


//创建
treeviewitem l_tvi
string ls_label
long ll_id
integer li_ord
long ll_handle

if ids_cata.rowCount() > 0 then
ls_label=ids_cata.object.cata_nm[1]
ll_id = ids_cata.object.cata_id[1]
l_tvi.label = ls_label
l_tvi.data = "c"+String(ll_id)
l_tvi.pictureindex = 1
l_tvi.selectedpictureindex = 1
ll_handle =atv.InsertItemfirst(0,l_tvi)
atv.SelectItem (ll_handle)
wf_buildnextlevel(atv,ll_id,ll_handle,ai_type)
else
return -1
end if

return ll_handle


--------------------------------------------------------
wf_buildnextlevel

long ll_found

ll_found = ids_cata.Find("parent_id ="+string(al_cataid),1, ids_cata.RowCount())


if ll_found>0 then
string ls_label
long ll_id,ll_pid
integer li_lv,li_ord
long ll_handle
int i
treeviewitem l_tvi
for i=ll_found to ids_cata.rowCount()
ls_label=ids_cata.object.cata_nm[i]
ll_id=ids_cata.object.cata_id[i]
ll_pid =ids_cata.object.parent_id[i]
if ll_pid = al_cataid then
l_tvi.label = ls_label
l_tvi.data = "c"+String(ll_id)
l_tvi.pictureindex = 2
l_tvi.selectedpictureindex = 3
ll_handle = atv.insertitemlast(ai_phandle,l_tvi)
wf_buildnextlevel(atv,ll_id,ll_handle,ai_type)
end if
next
return ll_handle
else
return ll_found
end if

li_d_s 2004-12-23
  • 打赏
  • 举报
回复
方法很多,递归最省,但是思路必须要清晰
meijiu 2004-12-23
  • 打赏
  • 举报
回复
递归函数
Raulgodle 2004-12-23
  • 打赏
  • 举报
回复
wu_07(我爱小婧):谢谢你的思路,不过条是不通,能否详细说明一下!
meijiu 2004-12-23
  • 打赏
  • 举报
回复
wu_07(我爱小婧),wf_buildnextlevel(atv,ll_id,ll_handle,ai_type) 最后一个参数是什么意思?
aichangfeng 2004-12-22
  • 打赏
  • 举报
回复
自己看看应该有很多
balloonman2002 2004-12-22
  • 打赏
  • 举报
回复
参考PB自带的CODE EXAMPLE中关于TREE的例子

604

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 控件与界面
社区管理员
  • 控件与界面社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧