2017-04-25 25 views
0
self.getDocumentCount().then(function (text) { 
     var stringArray = text.split("("); 
     count = stringArray[0].trim(); 
    }).then(function() { 
     self.logger.info("Document text : " + count, self); 
    }); 
    self.logger.info("Checking the count again : " + count, self); 

我無法獲得承諾外的價值。無法在量角器中分配承諾範圍外的變量

我用的量角器+的JavaScript +茉莉

+0

'getDocumentCount()'這是什麼輸出?我的意思是console.log(文本)給你什麼輸出? –

+0

承諾內的console.log(文本)爲我提供了文檔數量(即所需的結果)。如果我試圖在承諾之外獲取相同的值,我將得到undefined –

+0

因此,不能將結果存儲在承諾中返回的結果中嗎? –

回答

-1

您是否嘗試過這個在即代碼片段的最後一個計數變量?

var tempObject = {} 

it('should get count', function() { 
     getDocumentCount(strDoc); 
}); 

it('should display count', function() { 
     console.log(tempObject.Count); 
}); 

function = getDocumentCount(text) { 
    var stringArray = text.split("("); 
    tempObject.Count = stringArray[0].trim(); 
}) 
+0

您能否爲我提供tempObject的更多信息 –

+0

tempObject是示例代碼中的數組變量。 但是,如果你喜歡,你也可以使用一個正常的變量。 –