创建数组变量
我想创建这种输出
var s1 = [['Sony',7],['Samsung',5],['LG',8]];
这样我就可以用它来传递我的图形作为变量
从我的ajax的resutl出来
success: function(data){ //code to extract the data value here var s1= need to create the data here $.jqplot('chart',[s1],{ blah blah blah }
success函数中的“data”返回此表格布局
Sony 7 Samsung 5 LG 8
你能帮助我为此创造逻辑吗?
提前致谢
编辑:我正在寻找类似以下的解决方案:
var s1; $(".tblRows").each(function(){ // here I don't know exactly on what to do //s1.push($(".clsPhone").text(),$(".clsRating").text())); }); // all I wanted is to make the resul s1=[['Sony',7],['Samsung',5],['LG',8]];
因为jqplot需要这种参数
s1=[['Sony',7],['Samsung',5],['LG',8]]; $.jqplot('chart',[s1],{ renderer:$.jqplot.PieRenderer, rendererOptions:{ showDataLabels:true, dataLabelThreshold:1 } } });
所以我正在寻找一种方法来从数据中创建变量s1的值这可能吗?
var s1 = []; $(".tblRows").each(function(){ // create a temp array for this row var row = []; // add the phone and rating as array elements row.push($(this).find('.clsPhone').text()); row.push($(this).find('.clsRating').text()); // add the temp array to the main array s1.push(row); });
你可以这样做:
var row = []; $(".tblRows").each(function () { row.push([$(this).find('.clsPhone').text(), $(this).find('.clsRating').text()]); }); $.jqplot('chart', [row], { //... });