2017-07-30 46 views
0

以下是我與URL(http://localhost:3000/data將數據插入使用jquery表從URL讀數據返回JSON

[{"emp_id":5,"emp_city":"Hyderabad","emp_name":"Sam","emp_phone":"9999999999","emp_sal":"406000"},{"emp_id":1,"emp_city":"Hyderabad","emp_name":"ram","emp_phone":"9999999999","emp_sal":"50000"},{"emp_id":2,"emp_city":"Hyderabad","emp_name":"robin","emp_phone":"9999999999","emp_sal":"406000"},{"emp_id":4,"emp_city":"Hyderabad","emp_name":"krish","emp_phone":"9999999999","emp_sal":"406000"},{"emp_id":6,"emp_city":"Banglore","emp_name":"Bobby","emp_phone":"9999999999","emp_sal":"516000"},{"emp_id":3,"emp_city":"Chennai","emp_name":"rahman","emp_phone":"9999999999","emp_sal":"45000"}] 

下面讓我的JSON數據是jQuery腳本我試圖把數據表從上面的JSON

(function() { 
    // Create the connector object 
    var myConnector = tableau.makeConnector(); 

    // Define the schema 
    myConnector.getSchema = function(schemaCallback) { 
     var cols = [{ 
      id: "emp_id", 
      dataType: tableau.dataTypeEnum.int 
     }, { 
      id: "emp_city", 
      dataType: tableau.dataTypeEnum.string 
     }, { 
      id: "emp_name", 
      dataType: tableau.dataTypeEnum.string 
     }]; 

     var tableSchema = { 
      id: "emp", 
      alias:"test", 
      columns: cols 
     }; 

     schemaCallback([tableSchema]); 
    }; 

    // Download the data 
    myConnector.getData = function(table, doneCallback) { 
     $.getJSON("http://localhost:3000/data", function(resp) { 
      var feat = resp.features, 
       tableData = []; 

      // Iterate over the JSON object 
      for (var i = 0, len = feat.length; i < len; i++) { 
       tableData.push({ 
        "emp_id": feat[i].emp_id, 
        "emp_city": feat[i].emp_city, 
        "emp_name": feat[i].emp_name, 

       }); 
      } 

      table.appendRows(tableData); 
      doneCallback(); 
     }); 
    }; 

    tableau.registerConnector(myConnector); 

    // Create event listeners for when the user submits the form 
    $(document).ready(function() { 
     $("#submitButton").click(function() { 
      tableau.connectionName = "Employee Details"; // This will be the data source name in Tableau 
      tableau.submit(); // This sends the connector object to Tableau 
     }); 
    }); 
    })(); 

下面是我得到的 WDC報告了一個錯誤的錯誤: 遺漏的類型錯誤:無法讀取未定義堆棧的特性「長度」:類型錯誤: 不能再廣告屬性「長度」未定義在Object.success (http://localhost:8888/Examples/js/earthquakeUSGS.js:34:39)在j

請幫助解決它。

+0

響應數據中沒有屬性'features' ...它是一個數組,除非顯示的json不完整。因此,'壯舉'是不確定的,沒有'長度' – charlietfl

+0

我是jQuery的新手,請你幫我讀一下表格。 – Padma

+0

嘗試'var feat = resp' – charlietfl

回答

0

這裏:

var feat = resp.features, 
       tableData = []; 

沒有features財產。