Geofire文档说Geofire在读写数据时会返回承诺,但我似乎找不到任何这样的例子。我想知道如何在javascript中使用它来将一个函数附加到监听程序的末尾,该监听程序在geofire承诺实现时触发。我的代码是:
var onKeyEnteredRegistration = this.geoQuery.on("key_entered", function(key, location, distance) {
console.log(key + " entered query at " + location + " (" + distance + " km from center)");
}).then(function(result){
console.log("promise resolved with:" + result);
}, function(error){
console.error(error)
});但是这会输出一个错误,说'undefined is not a function‘引用了链接的函数。有人知道如何在Geofire中使用promises吗?
谢谢
发布于 2018-07-26 04:31:44
因此,只有GeoFire类上的get、set和remove函数返回promises。如下所示:
geoFire.get("some_key").then(function(location) {
if (location === null) {
console.log("Provided key is not in GeoFire");
}
else {
console.log("Provided key has a location of " + location);
}
}, function(error) {
console.log("Error: " + error);
});但是,on函数返回一个GeoQuery,它的on函数返回一个GeoCallbackRegistration,用于终止cancel函数的查询(该函数不返回任何内容)。
var onKeyEnteredRegistration = this.geoQuery.on("key_entered", function(key, location, distance) {
console.log(key + " entered query at " + location + " (" + distance + " km from center)");
});
onKeyEnteredRegistration.cancel(); // the "key_entered" event will stop firinghttps://stackoverflow.com/questions/45840546
复制相似问题