Azure Mobile服务中对表的正常调用如下:
var tbl1 = azureService.client.getTable('tbl1');
tbl1.where({PatientID:patientId}).read().done(
function(result){
},
function(err){
});
但当我尝试使用$时,我无法弄明白我应该怎么做。
$.when(tbl1.where({ PatientID: patientId }).read(),
tbl2.where({ PatientID: patientId }).read(),
tbl3.where({ PatientID: patientId }).read(),
tbl4.where({ PatientID: patientId }).read(),
tbl5.where({ PatientID: patientId }).read()).done(function (a,b,c,d,e) {
//hear a,b,c,d,e all are coming as promise() but not actual data
//how can I access data or the calling is not done right
}, function (err) {
console.log(err);
});
答案 0 :(得分:0)
read()
调用返回的对象不是延迟对象,而是承诺。您可以将其转换为承诺,然后使用$.when
方法。下面的代码显示了一种方法。
var table = client.getTable("movies");
var d1 = tableReadDeferred(table.where({ releaseYear: 2000 }));
var d2 = tableReadDeferred(table.where({ releaseYear: 2001 }));
$.when(d1, d2).done(function (r1, r2) {
$("#result1").text("Result 1: " + JSON.stringify(r1));
$("#result2").text("Result 2: " + JSON.stringify(r2));
});
}
function tableReadDeferred(query) {
var deferred = $.Deferred(function () {
query.read().done(function (result) {
deferred.resolve(result);
}, function (err) {
deferred.reject(err);
});
});
return deferred;
}