2017-04-06 99 views
0

Iam嘗試在我的Aurelia應用程序中爲jQuery使用Ajax自動完成。我不能訪問通過自動完成選擇的對象。 這是我的js代碼。Aurelia針對jQuery的Ajax自動完成

this.questionPaperLookup = $('#question-paper-list').autocomplete({ 
    lookup: this.questionPaperLookupData, 
    minChars : 0, 
    onSelect: function (suggestion) { 
    this.selectedQuestionPaper = suggestion.data; 
    } 
}); 

這裏的IAM設置selectedQuestionPaper基於從自動完成選擇。 並試圖從HTML訪問這個對象是這樣的:

<span id = "selected-question-paper" class="auto_text selected_batches"> 
      ${selectedQuestionPaper.name} 
      </span> 

但selectedQuestionPaper對象的名稱屬性沒有在視圖中顯示。我不知道缺少任何必需的步驟。在此先感謝

回答

0

您必須使用箭頭功能有詞法this

this.questionPaperLookup = $('#question-paper-list').autocomplete({ 
    lookup: this.questionPaperLookupData, 
    minChars : 0, 
    onSelect: (suggestion) => { 
    this.selectedQuestionPaper = suggestion.data; 
    } 
}); 
+0

問題使用前'this.selectedQuestionPaper = suggestion.data將一個調試器箭頭功能 –

+0

後依然存在;'看它是否被擊中 –

+0

是的。我可以打印對象屬性到控制檯likeconsole.log(this.selectedQuestionPaper.name);它打印選定的問題紙張名稱 –