0

I have a function like this:

function appendTable2(dinput,id) {
    return function(index, val) {
        $('#matrix_datatable').find(id)
            .append($('<td class="tableCells">')
                .append(val.value[0].dinput + '</td>')
            );
    };
}

And it's called like:

$.each(mainData.locations.source_values, appendTable2('address1','#mAddress'));

The problem is that this appends undefined to my table because of how this line works: .append(val.value[0].dinput + '</td>')

It's looking for an attribute in the object called dinput instead of the value of dinput. What's the proper syntax to use here?

jonmrich
  • 4,233
  • 5
  • 42
  • 94

1 Answers1

2

Append is not like string concatenation. When you append the first element it is done, no adding anything else to it.

So either you build the string

.append('<td class="tableCells">' + val.value[0][dinput] + '</td>') 

or set the text/html to the td

.append( $('<td class="tableCells"></td>').text(val.value[0][dinput]) ) 
epascarello
  • 204,599
  • 20
  • 195
  • 236