我使用的是無極庫來獲得與cheerio的請求的另一個諾言請求庫的結果,但不是布爾我不斷收到undefined
無極未定義的,而不是布爾
return Promise.try(function() {
.....
}).then(function() {
return self.checkGroupJoined(id);
}).then(function (data) {
console.log(data);
,我的方法與promise-request
this.checkGroupJoined = function (steam_id) {
var options = {
uri: 'url',
transform: function (body) {
return cheerio.load(body);
}
};
return rp(options).then(function ($) {
$('.maincontent').filter(function() {
if ($(this).find('a.linkTitle[href="url"]').length > 0){
return true;
} else {
return false;
}
});
}).catch(function (err) {
return error.throw('Failed to parse body from response');
});
};
我應該promisifyAll
庫嗎?
你...沒有從'rp(options).then(function($){')返回任何東西。你只需選擇一些元素,將它們過濾到一個子集,然後...扔掉它 –
so如何返回?因爲在識別它是否被發現之後返回? – Sandra
你想要返回什麼?因爲現在你只是修改元素的集合...沒有什麼可返回的? –