0
success: function( data ) {
                    response( $ac.map( data , function( item ) {
                        return {                               
                           label: '<a><table><thead><tr bgcolor="#9A9595"><th>AccName</th> <th>BillingCity</th> <th>BillingCountry</th></tr></thead> <tbody><tr><td width="50%">'+
                            item.AccName+'</td> <td width="70%">'
                            +item.BillingCity+'</td> <td width="70%"> '+item.BillingCountry+
                            '</td></tr></tbody></table></a>',
                            value: item.AccName
                        }
                    }));
                },
1
  • 1
    Just glancing at this, not knowing what data is (is it a list?), not knowing what $ac.map is, I suspect the problem is $ac.map is is constructing a map. Since you have <thead> in the JSON you're returning if data is in fact a list and $ac.map is performing some kind of iteration over that list, then it would stand to reason you have a bunch of table headers. But really we need to understand what data and $ac.map are before we can really be of help.
    – pchittum
    Commented Mar 19, 2015 at 11:04

1 Answer 1

1

You are mapping over an array, which will execute your map function once per element.

You can see that your map function adds the thead once for each element. You need to construct the actual table outside of the map, and only build the table row markup within the function that executes once for each item. Something like:

    var tableHead = '<a><table><thead><tr bgcolor="#9A9595"><th>AccName</th> <th>BillingCity</th> <th>BillingCountry</th></tr></thead> <tbody>';

    var tableBody = $ac.map( data , function( item ) {
        return '<tr><td width="50%">' + item.AccName + '</td> <td width="70%">' + item.BillingCity + '</td> <td width="70%"> ' + item.BillingCountry + '</td></tr>';
    });

    var tableEnd = '</tbody></table></a>';

    var table = tableHead + tableBody + tableEnd;

will build you a table, but I'm not sure how it fits into your wider problem as you don't say how the consuming code uses this and what label and value are for.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .