0

I am only able to access currentView and subTask, but not subTasks2. Although I'm following the same approach. I want to access the array of objects branches and report in the response. Any hint, please?

[
    {
        "id": "sss",
        "name": "TestDemo",
        "visibility": "ss",
        "projects": [
            {
                "name": "ss",
                "branchs": [
                    {
                        "name": "master",
                        "state": "none",
                        "report": {
                            "branchName": "master",
                            "projectName": "ss",
                            "organizationName": "TestDemo",
                            "failedRuns": 0,
                            "totalRuns": 0,
                            "successRunsPercentage": 100
                        }
                    }
                ]
            }
        ]
    }
]

Template vuejs (First two binds are working fine). I still want to access branchs and report


  <div id="ID1">
  <ul>
    <li v-for="currentView in responseTest" :key="currentView.id" >
      {{ currentView.name }} - {{ currentView.visibility }}
      <ul>
        <li v-for="subTask in currentView.projects " :key="subTask.id" >
          {{ subTask.name }} - {{ subTask.branchs }}
        </li>
      </ul>
      <ul>
        <li v-for="subTask2 in subTask.branchs " :key="subTask2.id" >
          {{ subTask2.name }} - {{ subTask2.state }}
        </li>
      </ul>
    
    </li>
  </ul>
</div>

1 Answer 1

1

The issue you're facing is that subTask is undefined in your third v-for due to incorrect nesting.

You can only access your variables assigned from the v-for inside child components of that element.

The element your subTask2 in subTask.branchs loop needs to be a child of the element that has the subTask variable.

For example:

    <div id="ID1">
        <ul>
          <li v-for="currentView in responseTest" :key="currentView.id">
            {{ currentView.name }} - {{ currentView.visibility }}
            <ul>
              <li v-for="subTask in currentView.projects" :key="subTask.id">
                {{ subTask.name }} - {{ subTask.branchs }}
                <ul>
                  <li v-for="subTask2 in subTask.branchs" :key="subTask2.id">
                    {{ subTask2.name }} - {{ subTask2.state }}
                  </li>
                </ul>
              </li>
            </ul>
          </li>
        </ul>
      </div>

You may need to play about with the structure and formatting to make it look right but that example should be runnable.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.