获取tfs迭代并使用jquery以树的形式显示

时间:2014-07-22 15:51:25

标签: c# jquery asp.net

这是我想要以树形结构形式填充的示例xml数据。

<Node NodeID="vstfs:///Classification/Node/ccd2111b-6ac1-4dfc-a3fd-0f0145f18822"     Name="Area" Path="\TestProjectByTFSAdmin_Ishwar\Area" ProjectID="vstfs:///Classification/TeamProject/86413a3a-6cc7-41bb-bef3-68177d5a0c14" StructureType="ProjectModelHierarchy">
    <Children>
        <Node NodeID="vstfs:///Classification/Node/711bb211-c51b-4555-ae71-0993239d4248"   Name="Inbox" ParentID="vstfs:///Classification/Node/ccd2111b-6ac1-4dfc-a3fd-0f0145f18822" Path="\TestProjectByTFSAdmin_Ishwar\Area\Inbox" ProjectID="vstfs:///Classification/TeamProject/86413a3a-6cc7-41bb-bef3-68177d5a0c14" StructureType="ProjectModelHierarchy" /> 
        <Node NodeID="vstfs:///Classification/Node/2a6fa306-2da2-457f-9dbd-fc02219d411f" Name="Recycle Bin" ParentID="vstfs:///Classification/Node/ccd2111b-6ac1-4dfc-a3fd-0f0145f18822" Path="\TestProjectByTFSAdmin_Ishwar\Area\Recycle Bin" ProjectID="vstfs:///Classification/TeamProject/86413a3a-6cc7-41bb-bef3-68177d5a0c14" StructureType="ProjectModelHierarchy" /> 
        <Node NodeID="vstfs:///Classification/Node/469b5304-fdc8-4d5d-aecd-32a75558dfbb" Name="TestArea" ParentID="vstfs:///Classification/Node/ccd2111b-6ac1-4dfc-a3fd-0f0145f18822" Path="\TestProjectByTFSAdmin_Ishwar\Area\TestArea" ProjectID="vstfs:///Classification/TeamProject/86413a3a-6cc7-41bb-bef3-68177d5a0c14" StructureType="ProjectModelHierarchy" /> 
    </Children>
</Node>

这个数据以字符串I的形式传递给下面的jQuery方法。

success: function (result) {
    var tree = $.parseXML(result.d);
    traverse($('#treeView li'),tree.firstChild)
    // this – is an &mdash;
    $('<b>–<\/b>').prependTo('#treeView li:has(li)').click(function(){
        var sign=$(this).text()
        if (sign=="–")
            $(this).text('+').next().children().hide()
        else
            $(this).text('–').next().children().show()
    })

    function traverse(node, tree) {
        var children = $(tree).children()
        node.append(tree.Name)
        if (children.length) {
            var ul = $("<ul>").appendTo(node)
            children.each(function () {
                var li = $('<li>').appendTo(ul)
                traverse(li, this)
            })
        } else {
            $('<ul><li>' + $(tree).text() + '<\/li><\/ul>').appendTo(node)
        }
    }
})

但是我没有在树结构中获得正确的值。

0 个答案:

没有答案