Tableau自定义Web数据连接器
我试图创建自定义Web数据连接器,我使用Tableau Web数据连接器教程中给出的示例。Tableau自定义Web数据连接器
我有一个链接,它以JSON的形式返回我的数据,并且我在jQuery AJAX函数中传递了这个URL,并试图对console.log结果进行处理。
但不幸的是,我收到了一个错误,如下所述。
Uncaught WDC error: Uncaught TypeError: Cannot read property 'results' of undefined stack:TypeError: Cannot read property 'results' of undefined
当我用jQuery一个AJAX请求不使用画面网络数据连接器的js文件,我能够从我们创建的链接检索数据。
当我比较yahooapi的结果和我们创建的链接时,数据就是这种格式。
雅虎API:
Object{*query*: Object}
从链接我们创建了:
[Object, Object, Object, Object]
这会不会有什么区别?
请帮我解决这个问题。
我意识到这是一个旧帖子,我不确定是否有人仍然需要这个问题的帮助,但我发布了自己的问题后发现它。过去一年中,我多次使用此REDCap WDC来创建自定义Tableau WDC。我知道这个例子专门用于连接REDCap数据,但是当我开始构建自定义的WDC时,WDC的格式/结构就是我所说的最多的。看看代码,你会发现它很有用。
(function() {
var myConnector = tableau.makeConnector();
// Define the schema
// myConnector.getSchema = function(schemaCallback){}
myConnector.getSchema = function(schemaCallback) {
var recordsInfo = [];
$.ajax({
url: JSON.parse(tableau.connectionData)['url'],
type: "POST",
data: {
token: JSON.parse(tableau.connectionData)['token'],
content: 'exportFieldNames',
format: 'json',
returnFormat: 'json',
type: 'flat',
rawOrLabelHeaders: 'raw',
exportCheckboxLabel: 'true',
exportSurveyFields: 'true',
exportDataAccessGroups: 'true'
},
contentType: "application/x-www-form-urlencoded",
dataType: "json",
success: function(resp){
recordsInfo = resp;
var recordSchema = [];
recordsInfo.forEach(function(field){
recordSchema.push({
id: field.export_field_name,
alias: field.original_field_name,
dataType: tableau.dataTypeEnum.string
});
});
var redcapTable = {
id: "redcap",
alias: "custom redcap extract",
columns: recordSchema
}
schemaCallback([redcapTable]);
}
});
};
// Download the data
myConnector.getData = function(table, doneCallback) {
var tableData = [];
$.ajax({
url: JSON.parse(tableau.connectionData)['url'],
type: "POST",
data: {
token: JSON.parse(tableau.connectionData)['token'],
content: 'record',
format: 'json',
returnFormat: 'json',
type: 'flat',
rawOrLabelHeaders: 'raw',
exportCheckboxLabel: 'true',
exportSurveyFields: 'true',
exportDataAccessGroups: 'true'
},
contentType: "application/x-www-form-urlencoded",
dataType: "json",
success: function(resp){
resp.forEach(function(record){
tableData.push(record);
});
table.appendRows(tableData);
doneCallback();
}
});
}
tableau.registerConnector(myConnector);
$(document).ready(function(){
$("#submitButton").click(function() {
tableau.connectionData = JSON.stringify({
'token': $("#token").val(),
'url': $("#url").val()
});
tableau.connectionName = "REDCap Data";
tableau.submit();
});
});
})();
尽管这个链接可能回答这个问题,但最好在这里包含答案的重要部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/17793320) –
我在Github项目中添加了一个代码片段。 – Dklaver
你能张贴能重现该问题的代码的样本?爱会帮助调试。 – lbrendanl
@lbrendanl - 能够连接并获取数据。 –