I want to display a database value and build a bootstrap grid, building the bootstrap grid was easy however displaying the data isn't as easily built.
Normally I would call the items I wanted in the loop like this x[i].DIAG;
. However I am building a dynamically variable name "s": var s = i*cNum+j
so that I can call the item dynamically x[s].DIAG
. When I display the value with console.log(s)
, I see the values I want. However, when I try output the data it breaks. Any suggestions would greatly be appreciated.
JSON example:
0: Object
DIAG:"Anaplastic"
DIAGID:13
Code:
function loadDiag(){
$.ajax({type: "GET"
, dataType: "json"
, url: "CFCs/lookUps.cfc"
, data: {method: "Diag_rlu"}
, success: function(data){
var x = data.items;
console.log(x)
var rNum = x.length / 6 //number of rows
var cNum = 6 // number of colums
var str = '';
for (var i = 0; i < rNum; i++) {
str += '<div class="row" id="'+i+'">';
for (var j = 0; j < cNum; j++) {
var s = i*cNum+j
if(s <= x.length){
str += '<div class="col-xs-2">'+x[s].DIAG+'</div>';
} else{
str += '<div class="col-xs-2"></div>';
}
}
str += '</div>';
}
$('.diagnosis').html(str);
}
});
}