2016-08-01 17 views
0

Ich habe mehrere Datensätze in der Tabelle .. Szenario, wenn ich auf Zeile dann Diagramm klicken ist Anzeige nach ID jetzt möchte ich angeben, welche Besitzer diese Daten haben, so dass ich versuche, den Namen des Besitzers anzuzeigen. .Wählen Sie Zellenwert aus Tabelle

ich habe Daten in einer Tabelle:

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

ich das versucht:

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

wenn ich f12 überprüfen dies zeigt den Fehler

WebForm1.aspx:109 Uncaught ReferenceError: cellvalue is not defined

+0

Ihr Cellvalue ist in ihrem Umfang nicht für Zeile: 'Text: JSON.stringify (Cellvalue)' –

+0

können Sie passieren Cellvalue zu 'GetData (obj) ; '' 'GetData (obj, cellvalue);'. –

+0

aber wenn ich diese Funktion GetData (obj, cellvalue) aufrufen, dann muss ich dort auch die Funktion GetData (obj) aufrufen .. ich will das nicht aufrufen .. ich will nur wenn wir in Zeile auswählen, dann will ich Besitzer bekommen Zellenwert im Label – user6628729

Antwort

0

Ändern Sie Funktion aufrufen und Funktionsdefinition:

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

und was ist mit "" ?? – user6628729

+0

Ich überprüfe. Ich werde dich wissen lassen, wenn ich eine Lösung finde. –

+0

Sie verwenden stringify, vielleicht erhalten Sie deshalb "". Können Sie die Variable direkt anstelle von json.stringify verwenden? –

Verwandte Themen