Angularjs 重复不起作用

Angularjs 重复不起作用,angularjs,json,Angularjs,Json,我可以获取这样的数组,我可以在控制台上看到它 0 : Object 1 : Object 2 : Object 3 : Object 4 : Object 5 : Object 6 : Object 7 : Object 8 : Object 9 : Object 10 : Object 11 : Object 12 : Object 13 : Object 14 : Object 15 : Object 16 : Object 17 : Object 18 : Object 每个数组都有这

我可以获取这样的数组,我可以在控制台上看到它

0 :  Object
1
:
Object
2
:
Object
3
:
Object
4
:
Object
5
:
Object
6
:
Object
7
:
Object
8
:
Object
9
:
Object
10
:
Object
11
:
Object
12
:
Object
13
:
Object
14
:
Object
15
:
Object
16
:
Object
17
:
Object
18
:
Object
每个数组都有这样的值,例如第0个数组包含

0:object
    id :  8726
    name : "aman"
    slug : "aman"
    type  :  "Drug"
角js

 $scope.keyup = function (data) {
   $http({
        url: 'myapi?q='+data,
     method: "GET", 
    }).success(function(response){

      $scope.results = response.data;
    });


 $scope.$watch('userInput',function(){
     var key =$scope.$$watchers[0].last;
     $scope.keyup(key) }); //this is because ng-keypress was not working but this is not an issue
HTML

使用跟踪

<a ng-repeat="item in $scope.results track by $index" ng-href="#">
            <div>{{item.name}}</div>
        </a>

<a ng-repeat="item in $scope.results track by item.id" ng-href="#">
            <div>{{item.name}}</div>
        </a>

这可能很傻,你能这样写,同时从api中得到如下结果吗

$scope.keyup = function (data) {
    $http({
        url: 'myapi?q='+data,
        method: "GET", 
    }).success(function(response){
      $scope.results = response.data.data;
    });
}
注意:您的keyup函数缺少右大括号。有一个 将代码复制到堆栈时可能会丢失。如果是这样,请忽略


下面一个可以帮助你

var app=角度。模块'exApp',[]; app.controller'Ctrl',['$scope','$http',函数$scope,$http{ $scope.searchMov=蝙蝠侠; $scope.data=[{'name':'aa','id':1,'address':'xxx'},{'name':'bb','id':2,'address':'zzz'},{'name':'cc','id':3,'address':'aaaa'},{'name':'dd','id':4,'address':'bbbbbb'}; //console.log$scope.data;//请参阅控制台 $scope.keyup=函数{ $http{url:'http://www.omdbapi.com/?s=“+$scope.searchMov+”&page=1”, 方法:获取, }.successfunctionresponse{ $scope.results=响应; }; }; 函数初始化{ $scope.keyup; }; 初始化; }]; {{data}} {{dat.id}{{dat.name}{{{dat.address}} 在此处搜索电影: {{results.Error}

{{rs.Title}{{rs.Year}}

根据提供的JSON,您的ng repeat代码工作正常

演示

var myApp=angular.module'myApp',[]; myApp.controller'MyCtrl',函数$scope{ var响应=[ { 身份证号码:8726, 姓名:aman, 斯拉格:阿曼, 类型:药物 }, { 身份证号码:8727, 姓名:aman1, 蛞蝓:aman1, 类型:药物1 }, { 身份证号码:8728, 姓名:aman2, 蛞蝓:aman2, 类型:药物2 }, { 身份证号码:8729, 姓名:aman3, 蛞蝓:aman3, 类型:Drug3 } ]; $scope.results=响应; };
html标记是否在编写keyup函数的控制器中?我可以像这样获取数组,并可以在控制台上看到它,您是指$scope.results吗?演示此问题的小示例非常好:您可以记录$scope吗。results@Shiva是的,我做了,它正在控制台上运行。。。您应该删除$scope
<a ng-repeat="item in $scope.results track by $index" ng-href="#">
            <div>{{item.name}}</div>
        </a>

<a ng-repeat="item in $scope.results track by item.id" ng-href="#">
            <div>{{item.name}}</div>
        </a>
$scope.keyup = function (data) {
    $http({
        url: 'myapi?q='+data,
        method: "GET", 
    }).success(function(response){
      $scope.results = response.data.data;
    });
}