2017-07-30 67 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财产。