1

I'm reading a JSON file which contains information about a number of users.

{
"SRM": [{
    "title": "Firstname Surname",
    "image": "firstname",
    "subtitle":"the subtitle"     
}, {
    "title": "Firstname Surname",
    "image": "firstname",
    "subtitle":"the subtitle" 
}, {
    "title": "Firstname Surname",
    "image": "firstname",
    "subtitle":"the subtitle" 
}]

}

The first part is working fine, in getting their details and building my HTML like so.

        $.getJSON("srm.json", function(data) {
        var i = 1;
        $.each(data.SRM, function(key, val) {

                 $("#image"+i).attr("src", "custom/img/who/"+val.image+".jpg");
                 $("#bioimage"+i).attr("href", "custom/img/who/"+val.image+"b.jpg");
                  $("#title"+i).html(val.title);
                   $("#subtitle"+i).html(val.subtitle);
                 i = i+1;

        });


    });

However I have now introduced tags, which will act as filters.

{
"SRM": [{
    "title": "CHETNA SHARMA",
    "image": "chetna",
    "subtitle":"SERVICE RELATIONSHIP MANAGER",
    "tags":["1","2","3"]
}]

}

I can't figure out how to correctly read these back so that I can add them all to the class of a user.

for example the above tags should add them like so

    <div id="thetags" class="cbp-item 1 2 3">

any pointers on how best to read out the whole tags array correctly? thanks

1

1 Answer 1

4
var tags = val.tags;
tags.join(" ");  // this will convert array to string.
Sign up to request clarification or add additional context in comments.

1 Comment

Glad to help :)

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.