Z
Z
zagamay_ru2015-12-10 11:21:38
Angular
zagamay_ru, 2015-12-10 11:21:38

How to display nested data in a loop?

Hello!
I take an array of data (comments) from the database, each comment can have a nested comment, and a nested comment can have a child comment, and so on.
Array example:

"models": [
    {
      "id": "122",
      "id_user": "3",
      "page": "Art-87",
      "id_parent": "0",
      "text": "йцуцуйцуйцу йцуйцуцйуцйу",
      "date_create": "2015-10-09",
      "time_create": "1444383408",
      "full_name": "Администратор",
      "service": "zagamay",
      "status": "1",
      "ip_user": "127.0.0.1"
    },
    {
      "id": "121",
      "id_user": "3",
      "page": "Art-87",
      "id_parent": "0",
      "text": "Тестовое соощение Два",
      "date_create": "2015-10-09",
      "time_create": "1444382461",
      "full_name": "Администратор",
      "service": "zagamay",
      "status": "1",
      "ip_user": "127.0.0.1",
      "Child": [
        {
          "id": "123",
          "id_user": "3",
          "page": "Art-87",
          "id_parent": "121",
          "text": "фывыфвфыв ыфвфывфыв фывфывфывфы вфыв",
          "date_create": "2015-10-09",
          "time_create": "1444383578",
          "full_name": "Администратор",
          "service": "zagamay",
          "status": "1",
          "ip_user": "127.0.0.1",
          "Child": [
            {
              "id": "125",
              "id_user": "3",
              "page": "Art-87",
              "id_parent": "123",
              "text": "фывыфвфыв ыфвфывфыв фывфывфывфы вфыв",
              "date_create": "2015-10-09",
              "time_create": "1444383584",
              "full_name": "Администратор",
              "service": "zagamay",
              "status": "1",
              "ip_user": "127.0.0.1",
              "Child": [
                {
                  "id": "120",
                  "id_user": "3",
                  "page": "Art-87",
                  "id_parent": "125",
                  "text": "Тестовое сообщение",
                  "date_create": "2015-10-09",
                  "time_create": "1444382324",
                  "full_name": "Администратор",
                  "service": "zagamay",
                  "status": "1",
                  "ip_user": "127.0.0.1",
                  "Child": [
                    {
                      "id": "124",
                      "id_user": "3",
                      "page": "Art-87",
                      "id_parent": "120",
                      "text": "фывыфвфыв ыфвфывфыв фывфывфывфы вфыв",
                      "date_create": "2015-10-09",
                      "time_create": "1444383581",
                      "full_name": "Администратор",
                      "service": "zagamay",
                      "status": "1",
                      "ip_user": "127.0.0.1"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ],

As you understand, nesting can be any. In php, it’s not a problem to display this at all, we make a function and restart it inside, the loop continues until the entire array has passed.
But how to display it in angular?
<div ng-repeat="item in comments.models">
       <!-- Вывод данных -->	
</div>

You can, of course, run the cycle inside again when checking for Child - But this is not a solution))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coderisimo, 2015-12-10
@zagamay_ru

recursive patterns?
benfoster.io/blog/angularjs-recursive-templates

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question