gpt4 book ai didi

jquery - 创建数组变量

转载 作者:行者123 更新时间:2023-12-01 06:13:32 25 4
gpt4 key购买 nike

我想创建这种输出

var s1 = [['Sony',7],['Samsung',5],['LG',8]];

这样我就可以用它来将我的图表作为变量传递

从我的ajax结果中得出

success: function(data){

//code to extract the data value here

var s1= need to create the data here

$.jqplot('chart',[s1],{ blah blah blah

}

成功函数中的“data”返回此表格布局

<table id="tblResult">
<tr class="tblRows">
<td class="clsPhone">Sony</td><td class="clsRating">7</td>
</tr>
<tr class="tblRows">
<td class="clsPhone">Samsung</td><td class="clsRating">5</td>
</tr>
<tr class="tblRows">
<td class="clsPhone">LG</td><td class="clsRating">8</td>
</tr>
</table>

你能帮我创建这个逻辑吗?

提前致谢

编辑:我正在寻找类似以下的解决方案:

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);
});

关于jquery - 创建数组变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5550911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com