0

I am using Javascript / Jquery to pull list data. One of the fields is Author, which is a group / people field that allows for multiple users. I get the data, and I test if there is data in the column then I loop through and append it to a table cell, the problem is how I gather it, I see what its doing, its going thru all the items. I don't know how to correct it though.

    //PRIMARY LIST DATA
    var dat=data.d.results;
//LOOPING THROUGH ALL OF THE DATA   
    for (var i=0;i<dat.length;i++){
//IF THE AUTHOR FIELD IS NOT DEFINED DO ANOTHER FOR LOOP
        if (dat[i].Author0.results === undefined){
            name='No author listed';
        }else {
            for (var j = 0;j < dat[i].Author0.results.length;j++){
                full = dat[i].Author0.results[j].Title;
            }
            name = full;
        }   
    tb+='<tr><td><a href="/Library/'+dat[i].FileLeafRef+'"><span class="doc-icons '+dat[i].File_x0020_Type+'"></span>'+dat[i].FileLeafRef+'</a></td><td>'+dat[i].Content_x0020_Type+'</td><td>'+keywd+'</td><td>'+name+'</td></tr>';
                    } 
                    $('.tb1> tbody').html(tb);
0

Is the code showing just the last user? Try this.

//PRIMARY LIST DATA
var dat=data.d.results;

//LOOPING THROUGH ALL OF THE DATA 
for (var i=0;i<dat.length;i++){ 
    //IF THE AUTHOR FIELD IS NOT DEFINED DO ANOTHER FOR LOOP
    var authors = dat[i].Author0.results;
    if (!authors){ 
        name='No author listed'; 
    }
    else{
        for (var j = 0;j < authors.length;j++){
            full += authors[j].Title + "; "; 
        }
        name = full;
    }
    tb+='<tr><td><a href="/Library/'+dat[i].FileLeafRef+'"><span class="doc-icons '+dat[i].File_x0020_Type+'"></span>'+dat[i].FileLeafRef+'</a></td><td>'+dat[i].Content_x0020_Type+'</td><td>'+keywd+'</td><td>'+name+'</td></tr>';
}
$('.tb1> tbody').html(tb);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.