0
then
という文脈でローカル変数x
にアクセスしたい場合はbind
を使用しますが、得られるのはx
です。 私はPromise
を使用してデータを取得しています。約束のローカル変数にアクセスして
AJAX呼び出しがこの機能で発生します:
function ajaxCall(){
p = new Promise(function(resolve, reject){
$.ajax({
url: 'http://localhost:9090/bru/struc/arrivals',
headers: { 'Authorization' : "Basic " + btoa("BRU:BRU")},
type: "GET",
success: function(data, status, xhr) {
resolve(data)
},
error: function(xhr, textStatus, errorThrown) {
xhr = reject
}
})
})
}
そして、ここで私は約束をアンラップし、x
function getColumns(){
var x
r = ajaxCall().then(function(result){
this.x.val = result \\result is available here, I can see it
console.log(result)
}.bind(this))
console.log('Columns retrieved.')
return x
}