Easyui Tree 노드 추가, 수정, 삭제 작업

4488 단어 java 기초
"text/javascript"</span>>
$(function(){
    $(<span class="hljs-string">"#contentCategory"</span>).tree({
        url : <span class="hljs-string">'/content/category/list'</span>,
        animate: <span class="hljs-keyword">true</span>,
        method : <span class="hljs-string">"POST"</span>,
        onContextMenu: function(e,node){
            e.preventDefault();
            $(<span class="hljs-keyword">this</span>).tree(<span class="hljs-string">'select'</span>,node.target);
            $(<span class="hljs-string">'#contentCategoryMenu'</span>).menu(<span class="hljs-string">'show'</span>,{
                left: e.pageX,
                top: e.pageY
            });
        },
        onSelect:function(node){
             $(<span class="hljs-keyword">this</span>).tree(<span class="hljs-string">'expand'</span>,node.target);
         },
        onAfterEdit : function(node){
            var _tree = $(<span class="hljs-keyword">this</span>);
            <span class="hljs-keyword">if</span>(node.id == <span class="hljs-number">0</span>){
                <span class="hljs-comment">//  </span>
                $.post(<span class="hljs-string">"/content/category/create"</span>,{parentId:node.parentId,name:node.text},function(data){
                <span class="hljs-comment">// 200</span>
                    <span class="hljs-keyword">if</span>(data.status == <span class="hljs-number">200</span>){
                        _tree.tree(<span class="hljs-string">"update"</span>,{
                            target : node.target,
                            id : data.data
                        });
                    }<span class="hljs-keyword">else</span>{
                        $.messager.alert(<span class="hljs-string">' '</span>,<span class="hljs-string">' '</span>+node.text+<span class="hljs-string">'  !'</span>);
                    }
                });
            }<span class="hljs-keyword">else</span>{
                $.post(<span class="hljs-string">"/content/category/update"</span>,{id:node.id,name:node.text});
            }
        }
    });
});
function menuHandler(item){
    var tree = $(<span class="hljs-string">"#contentCategory"</span>);
    var node = tree.tree(<span class="hljs-string">"getSelected"</span>);
    <span class="hljs-keyword">if</span>(item.name === <span class="hljs-string">"add"</span>){
        tree.tree(<span class="hljs-string">'append'</span>, {
            parent: (node?node.target:<span class="hljs-keyword">null</span>),
            data: [{
                text: <span class="hljs-string">' '</span>,
                id : <span class="hljs-number">0</span>,
                parentId : node.id
            }]
        }); 
        var _node = tree.tree(<span class="hljs-string">'find'</span>,<span class="hljs-number">0</span>);
        tree.tree(<span class="hljs-string">"select"</span>,_node.target).tree(<span class="hljs-string">'beginEdit'</span>,_node.target);
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(item.name === <span class="hljs-string">"rename"</span>){
        tree.tree(<span class="hljs-string">'beginEdit'</span>,node.target);
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(item.name === <span class="hljs-string">"delete"</span>){
        $.messager.confirm(<span class="hljs-string">' '</span>,<span class="hljs-string">'  '</span>+node.text+<span class="hljs-string">'  ?'</span>,function(r){
            <span class="hljs-keyword">if</span>(r){
                $.post(<span class="hljs-string">"/content/category/delete/"</span>,{parentId:node.parentId,id:node.id},function(){
                    tree.tree(<span class="hljs-string">"remove"</span>,node.target);
                }); 
            }
        });
    }
}

좋은 웹페이지 즐겨찾기