2

can someone help me this? I want to get the person id from the project, and bind it to a link to view more details of the person, but it doesn't look like a multidimensional array to me, any idea?

Angular js:

    var projects = [
    {
        id: 1, projectName: 'Economy', year: '2015', projectdescription: 'A cool economy project',
        persons: [
            { person: '1', personId:'1', firstname:'John', lastname:'Snow', description: 'John is an economist', expertise: 'Math' }
        ]
    }

Html:

<a href="#/projectpersons/{{projects.person.id}}" class="cardBody btn-link">View More</a>

Thanks in advance.

2
  • check my ans it should be the answer according to ur given json Commented Jul 12, 2015 at 7:31
  • you need ng-repeat to create your links. please look the code from @AshishRatan Commented Jul 12, 2015 at 22:36

3 Answers 3

3

You really need to learn about basic JavaScript stuff:

  • [a, b, c] (note the square brackets) is an array. You access to the element at index i, starting at 0, using array[i]
  • {name: 'Joe', age: 23} (note the curly brackets) is an object. You access to a property of this object using object.name or object['name'].

So what you have there is an array of projects. Each project is an object with a persons property, holding an array or persons. Each person is an object with a personId property.

So, to access the id of the first person of the first project, you would use

projects[0].persons[0].personId

To access the ID of the second person of the third project, you would use

projects[2].persons[1].personId
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, bad coder here. Looks like need a loop to bind each link to each person. Thanks.
2
<div ng-repeat='pr in projects'>
<div ng-repeat='p in pr.persons'>
{{p.person}}

<a href='#/ur/detail({pId:p.person})'>More detail</a>
</div>

</div>

Comments

0

Angular js:

`var projects = [
{
    id: 1, projectName: 'Economy', year: '2015', projectdescription: 'A cool economy project',
    persons: [
        { person: '1', personId:'1', firstname:'John', lastname:'Snow', description: 'John is an economist', expertise: 'Math' }
    ]
}`

html:

`<a href="#/projectpersons/{{projects[0].person[0].personId}}" class="cardBody btn-link">View More</a>`

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.