从表中选择单元格值

时间:2016-08-01 07:31:36

标签: javascript jquery highcharts

我在表格中有多条记录。当我点击行然后根据ID显示图表时,现在我想指定哪个所有者拥有此数据,所以为此我尝试显示所有者名称..

我在表格中有数据:

ID      Owner RegNo 
26626   John  B82       
26634   David BE49  
26642   Roh   A5    
26640   Julie B5    

我试过了:

 <script type="text/javascript">

    $(function () {
        $('#tabledata').on('click', 'tr', function () {
            var row = $(this);
            var Id = row.find('td')[0].firstChild.data;
            var cell = row.find('td')[1].firstChild.data;
            var obj = {};
            var cellvalue = {};
            obj.ID = Id;
            cellvalue.cell = cell;
            GetData(obj);
            return false;
        });
    });
function GetData(obj) {
    $.ajax({
        type: "POST",
        url: "WebForm1.aspx/GetVo",
        data: JSON.stringify(obj),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        cache: false,
        success: function (result) {
                   if (result !== null && result.length == 0) {
                $("#cont").hide();
                return;
            }
            strArray = result.d;
            var myarray = eval(strArray);
            $("#cont").show();
            $('#cont').highcharts({
                chart: {
                    borderColor: 'Grey',
                    borderWidth: 2,
                    type: 'pie',
                    options3d: {
                        enabled: true,
                        alpha: 45
                    }

                },

                title: {
                    text: JSON.stringify(cellvalue)
                },

                position: {
                        align: 'right',
                        verticalAlign: 'bottom',
                        x: 10,
                        y: -10
                  },
                subtitle: {
                    text: 'Chart'
                    //text: 'Total: ' + myarray.length
                },


                plotOptions: {
                    pie: {
                        innerSize: 100,
                        depth: 45,
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            format: '<b>{point.name}</b>: {point.y}',
                        },
                        showInLegend: true
                    }
                },
                series: [{
                    name: 'Delivered amount',
                    data: myarray
                }]
            });

            //end
        },
        error: function (error) {
            alert(error);
        }

    });
        }

    //  });


  </script>

当我检查f12时,显示错误

  

WebForm1.aspx:109未捕获的ReferenceError:未定义cellvalue

1 个答案:

答案 0 :(得分:0)

修改函数调用和函数定义:

<script type="text/javascript">

    $(function () {
        $('#tabledata').on('click', 'tr', function () {
            var row = $(this);
            var Id = row.find('td')[0].firstChild.data;
            var cell = row.find('td')[1].firstChild.data;
            var obj = {};
            var cellvalue = {};
            obj.ID = Id;
            cellvalue.cell = cell;
            GetData(obj, cellvalue); //HERE
            return false;
        });
    });
function GetData(obj, cellvalue) { //AND HERE
    $.ajax({
        type: "POST",
        url: "WebForm1.aspx/GetVo",
        data: JSON.stringify(obj),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        cache: false,
        success: function (result) {
                   if (result !== null && result.length == 0) {
                $("#cont").hide();
                return;
            }
            strArray = result.d;
            var myarray = eval(strArray);
            $("#cont").show();
            $('#cont').highcharts({
                chart: {
                    borderColor: 'Grey',
                    borderWidth: 2,
                    type: 'pie',
                    options3d: {
                        enabled: true,
                        alpha: 45
                    }

                },

                title: {
                    text: JSON.stringify(cellvalue)
                },

                position: {
                        align: 'right',
                        verticalAlign: 'bottom',
                        x: 10,
                        y: -10
                  },
                subtitle: {
                    text: 'Chart'
                    //text: 'Total: ' + myarray.length
                },


                plotOptions: {
                    pie: {
                        innerSize: 100,
                        depth: 45,
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            format: '<b>{point.name}</b>: {point.y}',
                        },
                        showInLegend: true
                    }
                },
                series: [{
                    name: 'Delivered amount',
                    data: myarray
                }]
            });

            //end
        },
        error: function (error) {
            alert(error);
        }

    });
        }

    //  });


  </script>