1

I am trying to send multi nested object to the html code but nothing work with me?

this is the server side script

for(var i=0; i<10; i++){
    var countries= [{
        userName:"TEST",
        email:"[email protected]",
        cities:[
            {name: "Riyadh"},
            {name: "Jeddah"},
            {name: "Qasim"}
        ]
    }];
    data.countries.push(countries);
}

and from the HTML this is my code

username email city
</tr>
   <tr      ng-repeat="country in data.countries">

    <td >{{::country.userName}}</td>
            <td >{{::country.email}}</td>
     
     <td>
       <span   ng-repeat="city in country.cities">
             {{::city.name}}
       </span>

     </td>
</tr>

1 Answer 1

1

It's not working because you define an array with an object then push that array onto your array, simply remove the outer array.

from: var countries = [{}]

to: var countries = {}

Or just push the object to the array, no need to assign it to a var first:

for (var i=0; i < 10; i++) {
    data.countries.push({
        userName:"TEST",
        email:"[email protected]",
        cities:[
            {name: "Riyadh"},
            {name: "Jeddah"},
            {name: "Qasim"}
        ]
    });
}
Sign up to request clarification or add additional context in comments.

7 Comments

np, glad to help
its works fine now but let me ask you something please
I think that warrants another question
its a simple question, I need to set the value into the city key through the server(GlideRecord)
while(getusers.next()) { var countries= { userName:"TEST", email:"[email protected]", cities:[ {name: "Riyadh"}, {name: "Jeddah"}, {name: "Qasim"} ] }; data.countries.push(countries); }
|

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.