簡體   English   中英

從表中選擇單元格值

[英]Select cell value from table

我在表中有多個記錄..場景,當我單擊行然后按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:未定義單元格值

修改您的函數調用和函數定義:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM