私はtableauで作業しています。自分のWebデータコネクタを構築する必要があります。 私はそれを書いて、それは完全にクロムで動作します。私はタブローにそれを使用するとき は、しかし、私はfoolowingエラーを取得:TableauでPromiseを使ってJsonを解析する
ReferenceError: Can't find variable: Promise file: http://localhost:9000/json-connector line: 246
私コネクタは2つの部分に分かれています。最初の部分は、目的地のリストを取得し、その名前で2つのリストを記入するWebサービスを呼び出します。 2番目の部分は、別のWebサービスを呼び出して、選択された2つの宛先間のすべてのパスを取得します。
最初のリストを取得するときにエラーが発生しました。私はそれがクロムには作用するが、タブローには作用しないと主張したい。
、エラーが発生したコードの一部:
var getJSON = function(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
resolve(xhr.response);
} else {
console.log("Something went wrong with the destination")
reject(status);
}
};
xhr.send();
});
};
私はタブローは約束をサポートしていないと思います。しかし、私は回避策を作る方法を知らない。ご協力いただきありがとうございます!
getJSON('http://localhost:9000/stations').then(function(data) {
//alert('Your Json result is: ' + data.result); //you can comment this, i used it to debug
//result.innerText = JSON.stringify(data); //display the result in an HTML element
console.log("starting parsing on : " + data.length);
var listArrival = document.getElementById('Arrival'); //get the list where you want to add options
var listDeparture = document.getElementById('Departure');
if(listArrival == null || listDeparture == null) console.error("Impossible to retrieve the list")
var op;
var addedStations = [];
for(var i = 0; i < data.length ; i++){
var obj = data[i];
var overflowControler = 0;
for(var key in obj){
console.log(key + '=' + obj[key]);
if(key == 'name' && addedStations.indexOf(obj[key]) == -1){
op = new Option(obj[key], obj['nlc'], true);
op2 = new Option(obj[key], obj['nlc'], true);
if(op == null) console.error("Impossible to create the new option")
listArrival.add(op);
listDeparture.add(op2);
addedStations.push(obj[key]);
}
overflowControler ++;
if(overflowControler > maxLengthOfEachRecordFromJson) break; // overflow control
}
if(i > maxStationsRecordNumberFromJson) break; //overflow control
}
}, function(status) { //error detection....
alert('Something went wrong.');
});
外部Promiseライブラリをあなたのtableauプロジェクトに含めることができますか(それが正しい名前であれば、私はtableauについてよく分かりません)? – Tomalak
私はjsはいにいくつかのライブラリを含めることができます! 例: –
これらのいずれかを含める:https://cdnjs.com/#q=promise - dは 'bluebird'に行きますが、必要なのは基本的なES6の約束だけであれば、より軽量な' es6-promise'ができます。 – Tomalak