gpt4 book ai didi

javascript - angucomplete-alt 从远程 url 获取数据的问题

转载 作者:行者123 更新时间:2023-12-02 16:49:39 26 4
gpt4 key购买 nike

我正在使用 angucomplete-alt 指令根据 get 请求创建自动完成列表。

当我使用 github api 时

<div angucomplete-alt id="ex5" placeholder="Search projects" pause="500" selected-object="selectedProject" remote-url="https://api.github.com/search/repositories?q=" remote-url-data-field="items" search-fields="name" title-field="name" minlength="2" input-class="form-control form-control-small" match-class="highlight"></div>

它返回结果没有问题。

当我尝试使用 jsonplaceholder 示例 api 时

<div angucomplete-alt id="ex5" placeholder="Search posts" pause="500" selected-object="selectedProject" remote-url="http://jsonplaceholder.typicode.com/posts/" search-fields="id" title-field="title" minlength="1" input-class="form-control form-control-small" match-class="highlight"></div>

我无法返回结果,但是当我查看控制台时,它正在加载内容(示例输入 22),但我无法让任何内容出现在自动完成列表中。

我能看到的唯一区别是结构。我已从 jsonplaceholder 中删除了remote-url-data-field="items",我没有收到任何错误,我在这里可能做错了什么?

工作 github 示例被注释掉。

http://codepen.io/anon/pen/pBfog

    <html class="no-js" id="ng-app" ng-app="app">
<head>
<title>Angucomplete Alt: Autocomplete Directive for AngularJS</title>
<meta name='viewport' content='width=device-width,initial-scale=1'>
</head>
<body ng-controller="MainController">
<div>
<div class="large-padded-row">
<div class="padded-row">
<!--
<div angucomplete-alt id="ex5" placeholder="Search projects" pause="500" selected-object="selectedProject" remote-url="https://api.github.com/search/repositories?q=" remote-url-data-field="items" search-fields="name" title-field="name" minlength="2" input-class="form-control form-control-small"
match-class="highlight"></div>
-->
<div angucomplete-alt id="ex5" placeholder="Search posts" pause="500" selected-object="selectedProject" remote-url="http://jsonplaceholder.typicode.com/posts/" search-fields="id" title-field="title" minlength="1" input-class="form-control form-control-small" match-class="highlight"></div>
</div>
<div class="result">
<div class="" ng-show="selectedProject">
Repository: <span class="bold-span">{{selectedProject.originalObject.git_url}}</span>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-touch.min.js"></script>
<script src="js/libs/angucomplete-alt.js"></script>
<script>
var app = angular.module('app', ["ngTouch", "angucomplete-alt"]);

app.controller('MainController', ['$scope', '$http',
function MainController($scope, $http) {
}
]);
</script>
</div>
</body>
</html>

最佳答案

来自 jsonplaceholder 的响应没有根对象。这就是原因。 Angucomplete-alt 不支持没有根对象的 JSON 对象。

关于javascript - angucomplete-alt 从远程 url 获取数据的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26793554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com