Topic
13 replies Latest Post - ‏2013-02-02T20:00:22Z by SystemAdmin
SystemAdmin
SystemAdmin
7615 Posts
ACCEPTED ANSWER

Pinned topic (JS) to get the length of a List object in a List object.

‏2013-01-30T14:31:09Z |
Hello guys, the main target is to get the length of "a List object" that is a variable of "a List object". I really need a piece of advice here. Let me explain it as follows ;

I have a special data type called myStruct which is composed of the following variables ;
myStruct
  • id (string)
  • myList (myStruct)(List)

  • In the human service -

I created a list of myStruct objects in my human service as follows ; myWholeList (myStruct) (List) . I believe it is so far so clear . This myWholeList object is full of a result of a service call. I debugged it and it works pretty fine meaning that all of the data inside of it is printable in a textArea. Briefly, it is for sure that myWholeList collection has sufficient amount of data.
  • In the coach view -
Now my purpose is to pass this myWholeList object of my human service into a coachView so that I will be able to make use of this object with JavaScript. That's why I also created a myWholeListJS (myStruct) (List) object under Configuration Options of my Coach view , AND , I binded it to the myWholeList object of my human service.

So I can honestly talk about such structure ; myWholeList (myStruct) (List) <-> myWholeListJS (myStruct) (List)

  • In the EventHandlers load() function of the coach view

I can write such a command and print its value as follows ;
var theList = this.context.options.myWholeListJS.get("value");
window.alert(theList.length()); // result : 25
window.alert(theList.get(0).id) ; // result : 010
Afterwards, when it is intended to reach the "myList <List> " property of the myWholeListJS, a problem arises.
I am not able to say ; window.alert(theList.get(0).myList.length()) . // here I expect to get the length of myList array object in theList array object.

Can anybody help please ? pretty miserable here .

I already appreciate your help.

Regards ,

Serhat
Updated on 2013-02-02T20:00:22Z at 2013-02-02T20:00:22Z by SystemAdmin
  • kolban
    kolban
    3314 Posts
    ACCEPTED ANSWER

    Re: (JS) to get the length of a List object in a List object.

    ‏2013-01-30T15:38:40Z  in response to SystemAdmin
    Try the following:

    
    theList.get(0).get(
    "value").myList.length()
    


    If it works ... post back. See if you can't piece together why this works and your's doesn't. If you have questions, I'll be delighted to try and help but first let us make sure this works.

    And please ... don't be miserable. It makes me sad when you are miserable.

    Neil
    • SystemAdmin
      SystemAdmin
      7615 Posts
      ACCEPTED ANSWER

      Re: (JS) to get the length of a List object in a List object.

      ‏2013-01-31T07:45:05Z  in response to kolban
      Hello Neil, thanks for the answer. No more using the word "miserable" then :) .
      When I try to print with window.alert( theList.get(0).myList ) ; It prints object object on the screen meaning I believe that there is something in it. However I cannot go further.

      None of the followings seem to work ;

      I try to give an alert with the following values in order to see at least object object on the screen, but not working.

      • theList.get(0).get("value")
      • theList.get(0).myList.get("value");
      • theList.get(0).myList.get(0);
      • kolban
        kolban
        3314 Posts
        ACCEPTED ANSWER

        Re: (JS) to get the length of a List object in a List object.

        ‏2013-01-31T17:17:40Z  in response to SystemAdmin
        I guess it isn't clear to me the exact structure of your data. Can you capture some screen shots of the data structure bound to your Custom Coach View. i.e. what I want to see is the nesting and data types of the variable type bound to your coach view.

        Neil
        • SystemAdmin
          SystemAdmin
          7615 Posts
          ACCEPTED ANSWER

          Re: (JS) to get the length of a List object in a List object.

          ‏2013-01-31T18:44:29Z  in response to kolban
          Hello Neil, let me explain it comprehensively then ;

          I would like to have a treeView thats why I am out after having such a structure that may enable me to create a dojo.tree.
          I have a data structure as follows ;

          Data Type : treeStructure
          Parameters :
          itself(tFolderPlan)
          children(tFolderPlan)(List)
          Data Type : treeStruct
          Parameters:
          main(tFolderPlan)
          children(treeStructure)
          I guess you can understand why I created such dataTypes. It is because when I create an object with the type treeStructure, I could have a structure that fits
          in the tree structure that I would like to end up with.

          So I create a Private object called ; treeDB(treeStructure)(List) . This allows me to have a tree like this ;

          Organization Folder :
          child : ----> Signature
          Management Folder :
          child : ----> File X
          child : ----> File Y
          HR Folder :
          child : ----> File HR
          In this example, each node is an object with the type of tFolderPlan that has attributes like ID, name, date, description etc.
          So when I say
          tw.local.treeDB[0].itself.aciklama + " : " ; result : "Organization Folder" .
          tw.local.treeDB[0].children[0].aciklama; result : "Signature".
          tw.local.treeDB[0].children.listLength ; result -> 1

          In my human service, I can print the tree into a textArea in a perfect way :) . But when it comes to transform it to a tree with the help of JavaScript , it is messed up.
          To create a treeView, I created a coachView called treeCoach. And inside of it , I have an object under Configuration options (see Image1) that is called
          treeDatabase(treeStructure)(List) just like the one defined in the human service. So I need to bind it to my object TreeDB, right ? because this is what I want
          to make use of with JS. Check image 2 to see the binding please. Afterwards, I go into load EventHandler function (image 3) and write some commands to benefit from
          the data I hold in my hands , treeDatabase .

          As Kolban's book shows :), this is how I get an object created in Configuration Option into load function.

          var myTree = []; myTree = this.context.options.treeDatabase.get("value");

          The rest of the code is in the code.txt file, I can build up my tree with only "myTree.get(counter).itself.aciklama" names as given in the Image treeImage of the attached zip file. However I can not insert myTree.get(counter).children[] names into my tree . In order for me to get the children, I need to reach the list inside of my list object. But I cannot seem to do that.

          I hope it is clear ,

          Thanks in advance.

          Regards,

          Attachments

        • SystemAdmin
          SystemAdmin
          7615 Posts
          ACCEPTED ANSWER

          Re: (JS) to get the length of a List object in a List object.

          ‏2013-01-31T18:51:53Z  in response to kolban
          Creating such structure for a treeView might be not a good idea. If you have some advice to create a treeview that allows the user to pick multiple nodes and do further operations with them such as update,delete etc , I also really appreciate. The difficult part for me in my scenario is to call a service and create a tree out of it wih JS. Passing the values from coach view to coach , or from coach to the load function of coach view can be
          really cruel sometimes. For instance I have difficulties to pass the id of clicked node of the tree into the coach. So If you ever needed to create such a tree and experienced how to overcome it, I really would like to benefit from your knowledge.

          Thanks again,

          Serhat
          • SystemAdmin
            SystemAdmin
            7615 Posts
            ACCEPTED ANSWER

            Re: (JS) to get the length of a List object in a List object.

            ‏2013-01-31T19:22:11Z  in response to SystemAdmin
            I guess the custom Dijit Widget in a Coach View is one of the options as you suggested me to read page 298 of Kolban's (Your)IBPM Book :) . I started to try this solution and spent my time on it , that's why I've not got a chance to apply a custom Dijit Widget for my problem. While we try to get that children list of the tree object, I will have a look at custom Dijit widget. I keep you posted.

            Regards,
          • kolban
            kolban
            3314 Posts
            ACCEPTED ANSWER

            Re: (JS) to get the length of a List object in a List object.

            ‏2013-01-31T19:23:50Z  in response to SystemAdmin
            Serhat,
            Have you looked at the following:

            http://bpmwiki.blueworkslive.com/display/samples/CV+-+Data+Tree+v2

            Why would this Tree Viewer not work?

            Neil
            • SystemAdmin
              SystemAdmin
              7615 Posts
              ACCEPTED ANSWER

              Re: (JS) to get the length of a List object in a List object.

              ‏2013-01-31T19:34:06Z  in response to kolban
              Thanks for the link Neil, however it is only a treeView I guess . I mean it is not possible to select multiple nodes like a checkbox Tree view.
              I need to create something like this http://ait.web.psi.ch/js/dojo/tests/widget/tree/test_tree_10.html. But again thanks for your support. However we still might need to do some operations with the list of a list object :) that's still a mystery for me . I keep you posted on any news.

              Regards,
              • kolban
                kolban
                3314 Posts
                ACCEPTED ANSWER

                Re: (JS) to get the length of a List object in a List object.

                ‏2013-01-31T19:45:55Z  in response to SystemAdmin
                It strikes me that the Coach Views on the Wiki are considered samples. What this means is that you can use them as the basis for your own Coach Views. Rather than starting from scratch, I am wondering if there isn't a way to use the existing sample Coach View as a basis for what you want. Starting from that Coach View, you may be able to modify it to add the check boxes. I'd also post a comment to the Coach View sample page to start a dialog with the author. Maybe he has other requests for such a feature and might be willing to add it himself?

                Neil
                • SystemAdmin
                  SystemAdmin
                  7615 Posts
                  ACCEPTED ANSWER

                  Re: (JS) to get the length of a List object in a List object.

                  ‏2013-01-31T19:54:51Z  in response to kolban
                  Hmm ok then Neil, I will do that . I appreciate your support.
                  Note : For the ones who look for a dojo example of tree view, this link may be beneficial.

                  http://www.thejekels.com/blog/featured/the-new-dijit-checkbox-tree/

                  Kind regards,
            • SystemAdmin
              SystemAdmin
              7615 Posts
              ACCEPTED ANSWER

              Re: (JS) to get the length of a List object in a List object.

              ‏2013-02-02T12:34:49Z  in response to kolban
              To mention the result of my effort on this problem, I can say that , weirdly "the list inside of an object list" sent by a coach, cannot be retrieved by the coach view .

              To explain it with another example, I created a dataType called listOflist that has the property "list<string>" . So when I create an object with listOfList type, I have something like "myList(listOfList)" . So myList is full of string lists like

              myList.list[0] = "apple";
              myList.list[1] = "orange";
              And I want it to be passed towards a coach view which I can do it successfully. In my coach view I am able to get those apple and orange values with the following command ;

              myCoachViewList <-> (binded to) <-> myList

              window.alert(myCoachViewList.get(0)) ;
              window.alert(myCoachViewList.get(1));

              It is so far so good . However somehow, I decide to have a list which includes many objects with the type of listofList which would mean to have such a structure ;

              myList<listoflist><list>

              so if I put some data in it as follows ;

              myList[0].list[0] = "apple";
              myList[0].list[1] = "orange";
              myList[1].list[0]= "melon";
              myList[1].list[1]= "watermelon";

              and if I want to pass it to my coach view , then a very annoying trouble occurs ! which is that the command below will not work in coach view part;

              myCoachViewList.get(0).list.get(0) ---> wont work
              or
              myCoachViewList.get(0).list[0] ) ---> wont work
              or
              myCoachViewList.get(0).list.length() ---> wont work

              What does not work is what I've figured out so far :) , if anyone can figure out how it could work, then please share it with us.

              Respects,
              • kolban
                kolban
                3314 Posts
                ACCEPTED ANSWER

                Re: (JS) to get the length of a List object in a List object.

                ‏2013-02-02T15:22:29Z  in response to SystemAdmin
                First of all, thank you for a well written posting. The fact that you took the time to clearly provide a description of what you were doing, what you tried and your conclusions was a great inspiration for me to spend time to research the issue to see if I could add anything to the story. Your description was crystal clear and I read it with great interest. After reading, I decided to play in my own sandbox to see what I could find.

                I tried the three suggestions that you concluded your posting with and was surprised that none of them worked. What I did next was insert a debugging statement using the JavaScript "debugger;" statement. I use the Chrome browser and when this statement is reached, the browser pauses and I can look at and examine variables. By looking at the structure of the variables returned from:

                1. myCoachViewList
                2. myCoachViewList.get(0)
                3. myCoachViewList.get(0).list
                
                myCoachViewList.get(0).list.items[0]; 
                // "apple" myCoachViewList.get(0).list.items[1]; 
                // "orange" myCoachViewList.get(1).list.items[0]; 
                // "melon" myCoachViewList.get(1).list.items[1]; 
                // "water melon"
                


                So what is this mysterious "items" object name? That I don't know yet. However, this recipe does seem to work for just now so wanted to pass that on in case we don't make any further progress in understanding the deeper picture.

                Neil
                • SystemAdmin
                  SystemAdmin
                  7615 Posts
                  ACCEPTED ANSWER

                  Re: (JS) to get the length of a List object in a List object.

                  ‏2013-02-02T20:00:22Z  in response to kolban
                  Neil,

                  That's so right ! , putting "items" next to the name of the list works perfectly. "items" is the key there. Now I am able to get the length of the list and more info about the objects in that list as follows ;

                  for(var counter=0 ; counter<myTree.length(); counter++)
                  {
                  var lengthOfChild = myTree.get(counter).children.items.length;
                  var childName = myTree.get(counter).children.items.name;
                  ...
                  ...

                  I am more than happy now :) I've been trying to modify the example you suggested for the tree "http://bpmwiki.blueworkslive.com/display/samples/CV+-+Data+Tree+v2". However it was a bit difficult for me to modify it in the way I want follow. Now I am able form a nice tree view with the data comes by a service call thanks to You. Next step for me is to allow the user to select multiple nodes on my tree which might be possible only with a checkbox which mean that my tree needs more modification. I will try to make that happen and when it does I will be glad to share it in the forum .
                  Thanks again,

                  Serhat