我可以按照以下说明在模拟器中使用WDC: enter link description here
但是我很难让它真正在Tableau中工作。我读这是因为调用的异步性质。
我正在尝试以下操作,但不起作用。我曾考虑过使用Promise,但是我很难确定要在哪里放置调用以及何时执行回调(我读到的是问题所在)
因此,如果有人可以帮助我了解Promise的工作原理或在下面帮助解决问题,我将不胜感激。
(function () {
var myConnector = tableau.makeConnector();
myConnector.getSchema = function (schemaCallback) {
var cols = [{
id: "date",
dataType: tableau.dataTypeEnum.date
},{
id: "rate",
dataType: tableau.dataTypeEnum.float
}];
var tableSchema = {
id: "EuroFX",
alias: "Daily Euro-USD Exchange Rates via Fixer API",
columns: cols
};
schemaCallback([tableSchema]);
};
function getDataForDate(date_string, successCallback) {
return $.getJSON("http://data.fixer.io/api/" + date_string + "?access_key=xxxxxx&symbols=USD"), successCallback();
};
myConnector.getData = function (table, doneCallback) {
var combinedData = [],
deferred = [];
var now = new Date();
var date_looper = new Date(2018,5,1);
while (date_looper < now){
var date_string = date_looper.getFullYear() + '-'
+ ('0' + (date_looper.getMonth() + 1)).slice(-2) + '-'
+ ('0' + (date_looper.getDate())).slice(-2);
deferred.push(getDataForDate(date_string, function (data) {
combinedData = combinedData.concat(data);
}));
date_looper.setDate(date_looper.getDate() + 1);
}
$.when(deferred).done(function() {
table.appendRows(combinedData);
doneCallback();
});
};
tableau.registerConnector(myConnector);
$(document).ready(function () {
// The event listener below isn't necessary when writing for running without user input
$("#submitButton").click(function () {
tableau.connectionName = "FX Rate Feed";
tableau.submit();
});
});
})(); d