1

If description value is empty the value should be created as a “Root Document and placed to the top of the list.

If description value is not empty the value should be created as a Folder name and title should be created as Root Document of “Folder Name”

If description value is equal to other description value in JSON data, they value should not be created a folder name it only created for Root Document of matched description value (Folder name).

If Description value is (one > two ) like that “two” should created as Sub folder of “one” and “title” value should be created as Root Document of Sub Folder (two).

HTMl :

<div ng-controller="TodoCrtl">
      <ul>
        <li ng-repeat="description in getDescriptions()" style="color:red;">
          {{description}}
          <ul>
            <li ng-repeat="bookmark in flaternedBookmarks|filter:{description:description}" style="color:blue;">
              {{bookmark.title}}
            </li>
          </ul>
        </li>
      </ul>
    </div>

JS File:

function TodoCrtl($scope) {

  $scope.names = [{
    "description": "Testing File",
    "totalCount": 6,
    "bookmarks": 
    [
        {
            "title": "Google",

            "description": "Health Care",

        },

        {
            "title": "Test Construction1",

            "description": "",

        },



        {
        "title": "one 1.1",

        "description": "one",

        }, 

        {
        "title": "one 1.2",

        "description": "one",

        }, 

        {
        "title": "Test Connection",

        "description": "Education",

        } ,
      {
        "title": "Project EA TEST 1",

        "description": "",

        },

        {
        "title": "one 2.1",

        "description": "one > two",

        },

        {
        "title": "one 2.2",

        "description": "one > two",

        }
    ]

}];



  $scope.getDescriptions=function(){
    var descriptions=[];
    $scope.flaternedBookmarks=[];
    var arr= $scope.names;
  angular.forEach(arr,function(ai){
     angular.forEach(ai.bookmarks,function(v){
      if(v.description.trim()==='')
        {

          descriptions.splice(0,0,v.title.trim());
        }else
          {

            descriptions.splice(descriptions.length-1,0,v.description.trim());
          }
      $scope.flaternedBookmarks.push(v);
    });
  });


    return descriptions.filter (function (v, i, a) { return a.indexOf (v) == i; });
  };

Now the issue is empty Ul was created in “Root Documents and how to add the logic of If Description value is (one > two ) like that “two” should created as Sub folder of “one” and “title” value should be created as Root Document of Sub Folder (two) in this script.

All root documents use same class and all the folder and sub folder use same class

Working Link JS bin

Expecting Format

1 Answer 1

1

You can check angular-ui-tree!

Sign up to request clarification or add additional context in comments.

1 Comment

I am try to without any plugins

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.