Quantcast
Channel: jQuery Library for SharePoint Web Services
Viewing all articles
Browse latest Browse all 6517

New Post: Treeview from MOSS 2007 List

$
0
0
@PaulM22

You are on the right track. Since you are getting items back from the list, you now have to format them in a way that you'd like for them to display. You'll want to do that by building up on big object and add that to the dynatree's options.

Admittedly, I've never used the SPXmlToJson function, so I'm not versed in using it. It'll probably be easier for you to roll your own thing anyway. Here's an example of what the hierarchy should look like as an object:
            children: [
                   {
                    title: "Root",
                    isFolder: true,
                    key: "Root",
                    children: [
                        {
                            title: "Folder 1",
                            isFolder: true,
                            key: "folder1",
                            id: 1,
                            children: [
                                {
                                    title: "Folder 3",
                                    isFolder: true,
                                    key: "folder3",
                                    id: 3
                                }
                            ]
                        },
                        {
                            title: "Yeah!!!",
                            id: 2
                        },
                        {
                            title: "Item 1",
                            id: 4
                        },
                        {
                            title: "Folder 2",
                            isFolder: true,
                            key: "folder2",
                            id: 5,
                            children: [
                                {
                                    title: "Sub-item 2.1",
                                    id: 6
                                },
                                {
                                    title: "Sub-item 2.2",
                                    id: 7
                                }
                            ]
                        },
                        {
                            title: "Item 3",
                            id: 8
                        }
                    ]
                }
            
So what I've done was build up the items and then make a call to dynatree within the "completefunc" ( I used CSOM, but whatev ):

  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "MOSS Fileplan",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Parent_URL' /><FieldRef Name='Process' /></ViewFields>",
    CAMLQuery: "<Query><Where><Eq><FieldRef Name='Parent_URL' /><Value Type='Text'>" + "S10" + "</Value></Eq></Where></Query>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).find("[nodeName='z:row']").each(function() {
        //alert(xData.responseXML.xml);
        var myJson = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
          mapping: {
            ows_ID: {mappedName: "ID", objectType: "Counter"},
            ows_Title: {mappedName: "MdbaUrl", objectType: "Text"},
            ows_Process: {mappedName: "Process", objectType: "Text"},
            ows_Parent_URL: {mappedName: "ParentUrl", objectType: "Text"}
          }, // name, mappedName, objectType
          includeAllAttrs: false,
          removeOws: true
        });

        // Build up your treeItems object then call the buildTree function and pass treeItems
        $(document).ready(function() {
              buildTreeItems( treeItems );
        });
        // To read a field it is ALWAYS $(this).attr("ows_<internal field name>");
        var liHtml = "<li>" + $(this).attr("ows_Process") + " (" + $(this).attr("ows_Title") + ")</li>";
        $("#tasksUL").append(liHtml);
      });
    }
  });


function buildTree(treeItems) {
        // Get the div id's for each tree
        // --- Initialize first Dynatree
        $("#tree").dynatree({
            autoFocus: false, // Set focus to first child, when expanding or lazy-loading.
            minExpandLevel: 0,
            children: treeItems
    });
}
That's one way of building the tree w/o relying on a .json file somewhere on a server. So really now all you have to do is build up your treeItems object in the format you want and you'll be done.

Let me know if you need help on building the object correctly. It can be a little tricky depending on your requirements. It CAN be done though. :-P

Cheers,
Matthew

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>