创建数组变量 [英] create array variable

查看:96
本文介绍了创建数组变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建这种输出

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

以便我可以使用它作为变量传递图形

so that I could use it to pass on my graph as a variable

退出我的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" in the success function returns this table layout

<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>

您能帮助我为此创建逻辑吗?

can you please help me create the logic for this?

预先感谢

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

I'm looking for a solution something like the following:

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需要这种参数

because jqplot requires this kind of parameter

s1=[['Sony',7],['Samsung',5],['LG',8]];
$.jqplot('chart',[s1],{
        renderer:$.jqplot.PieRenderer,
        rendererOptions:{
            showDataLabels:true,
            dataLabelThreshold:1
        }
    }
});

所以我正在寻找一种从数据中为变量s1创建值的方法 这有可能吗?

so I'm looking for a way to create a the value for the variable s1 out from the data could this be possible?

推荐答案

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

这篇关于创建数组变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆