私の質問は、この投稿「AngularJS アプリで typeahead と ajax を使用する」に非常に似ています
コーヒースクリプト:
$scope.tradingPartners = (searchOn) ->
console.log("Searching on #{searchOn}")
$.getJSON("../tp/tpLookupAdmin", {term: searchOn, max: 20}, (response)->
response)
Javascript を生成します。
$scope.tradingPartners = function(searchOn) {
console.log("Searching on " + searchOn);
return $.getJSON("../tp/tpLookupAdmin", {
term: searchOn,
max: 20
}, function(response) {
return response;
});
};
それを使用して:
<input type="text" ng-model="testScript.sender" typeahead="sender as sender.label for sender in tradingPartners($viewValue)"
では、何が問題なのですか?...
getJSON 呼び出しは正常に行われ、結果は良好に見えますが、先行入力は何もしません。関数からの戻り値としてハードコードされた値を入れると、問題なく動作します。
これで、getJSON がオブジェクト配列を返すだけではないことがわかりました。
$.getJSON("../tp/tpLookupAdmin", {term: searchOn, max: 20}, (response)->
response).responseJSON
undefined を返します。
動作するハードコードされた json の例:
[{"id":"1","label":"test1"},{"id":"2","label":"test2"}]
ここで簡単なものが欠けています...
編集(kju回答から):
現在、生成された JS は
$scope.tradingPartners = function(searchOn) {
return $http.post("../tp/tpLookupAdmin?term=" + searchOn).then(function(response) {
return limitToFilter(response, 15);
});
};
しかし、まだ機能していません...