1、 首先创建一个TREE控件
2、 在Tree下面创建一个TREE NODE TYPE ,node type 是可以继续展开的,而Item type是无法展开的.
3、 创建node.,下面的图是完成的node
创建在node下面创建递归treenode,递归treenode相当于node,node下面的属性在treenode中都有,就相当于一个dode展开后还有一个node下面的属性和node是一样的,一层有一层的。跟node结构一样。
创建属性,其中包括HAS_CHILDREN,它是类型是BOOLEAN。用于控制递归node是否可以展开.
返回到layout设计界面,tree控件的datasource需要绑定刚才建立的NODE
treenode的datasource需要绑定刚才建立的NODE,hasChildren也要绑定node中的hasChildren,iconSource绑定node中的icon,TEXT绑定node中的treetext.
4 、初始方法code:
method WDDOINIT .
DATA lo_nd_tree TYPE REF TO if_wd_context_node. DATA lt_tree TYPE wd_this->Elements_tree.
DATA ls_tree TYPE wd_this->Element_tree. ls_tree-TREETEXT = ''.
ls_tree-HAS_CHILDREN = abap_TRUE.
APPEND ls_tree to lt_tree. ls_tree-TREETEXT = ''.
ls_tree-HAS_CHILDREN = abap_TRUE.
APPEND ls_tree to lt_tree. ls_tree-TREETEXT = ''.
ls_tree-HAS_CHILDREN = abap_TRUE.
APPEND ls_tree to lt_tree.
CLEAR ls_tree. lo_nd_tree = wd_context->get_child_node( name = wd_this->wdctx_tree ).
lo_nd_tree->bind_table( new_items = lt_tree set_initial_elements = abap_true ). DATA lo_el_2nd TYPE REF TO IF_WD_CONTEXT_ELEMENT.
CALL METHOD LO_ND_TREE->GET_ELEMENT
EXPORTING
INDEX = "得到第二个
RECEIVING
NODE_ELEMENT = lo_el_2nd. DATA lo_nd_2nd_TREENODE TYPE REF TO IF_WD_CONTEXT_node. CALL METHOD LO_EL_2ND->GET_CHILD_NODE
EXPORTING
NAME = 'TREENODE' "递归node
RECEIVING
CHILD_NODE = lo_nd_2nd_TREENODE. REFRESH lt_tree. ls_tree-TREETEXT = '2.1'.
APPEND ls_tree to lt_tree. ls_tree-TREETEXT = '2.2'.
APPEND ls_tree to lt_tree. lo_nd_2nd_TREENODE->bind_table( new_items = lt_tree set_initial_elements = abap_true ).
endmethod.
5、运行效果