Child rows using ajax where url json returns multiple rows

Child rows using ajax where url json returns multiple rows

datamaskinaggiedatamaskinaggie Posts: 4Questions: 2Answers: 0

Howdy,
* I have a very good solution to the display of my child rows using the accordion effect.
* The child row is being populated via ajax using json returned from the server defined using the url:
* The returned JSON represents multiple rows not just 1.
* The success: function is just fetching the first row as json[0].
* The actual json map contains 20 rows.
* The data is modified using the $(cell).html() created cell function.
* This works great for 1 row.
* How to loop thru for multiple rows?

var container = $('<div>Loading...</div>');

            $.ajax( {
                url: '/server/getData',
                data: {
                    name: row.data()[1]
                },
                success: function ( json ) {
                    if ( json.length === 0 ) {
                        container.html( 'No data found' );
                    }
                    else {
                        var data = json[0];

                        var text = '';
                        var ascii = '';

                        for ( var i=0, ien=data.blob.length ; i<ien ; i++ ) {
                            text += String.fromCharCode( data.blob[i] );
                        }

                        ascii = hex2ascii(text);

                        container.html(
                            'Name: '+data.object_name+'<br>'+
                            'Mime: '+data.mime+'<br>'+
                            'Sequence: '+data.sequence+'<br>'+
                            // 'Data: '+text.substr(0, 30)+'...'
                            'Data: ' + ascii
                        );
                    }
                },
                error: function ( json ) {
                    container.html( 'Failed to load child content: '+row.data()[1] );
                }
            } );

Replies

  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin

    Instead of using var data = json[0];, you could use a for loop to loop over the array in the json variable, building up the output string before finally writing it to the container.

    Allan

This discussion has been closed.