使用AngularJS在主页面上未加载数据

时间:2016-04-03 08:08:01

标签: javascript angularjs json

我有简单的AngularJS应用程序,它从JSON读取数据并在页面上显示它。我还有几个过滤器来搜索数据。现在我面临的问题是,在我实现过滤器逻辑之后,数据没有显示在页面上。它是在我在我的代码中加入过滤之前显示的。

foll是渲染: image

foll是错误:

  

angular.js:13236错误:[filter:notarray]预期数组但收到:0       http://errors.angularjs.org/1.5.0/filter/notarray?p0=0           在angular.js:68           在angular.js:19280           at fn(eval at(angular.js:14086),:4:315)           在trackByIdExpFn(angular.js:28452)           在ngRepeatAction(angular.js:28509)           at $ watchCollectionAction(angular.js:16529)           在Scope。$ digest(angular.js:16664)           在Scope。$ apply(angular.js:16928)           完成时(angular.js:11266)           at completeRequest(angular.js:11464)(匿名函数)@ angular.js:13236(匿名函数)@ angular.js:9965Scope。$ digest @ angular.js:16682Scope。$ apply @ angular.js:16928done @ angular。 js:11266completeRequest @ angular.js:11464requestLoaded @ angular.js:11405

foll是我的JSON结构:

[    
  {
    "name": "George Eliot",
    "thoughts": ["thought 1", "thought 2", "thought 3"]   
  },

  {
    "name": "Nietzsche",
    "thoughts": ["thought 1", "thought 2", "thought 3"]    
  }    
]

foll是我在视图中的过滤器代码:

<md-input-container>
    <label>Enter Search Term</label>
    <input type="text" ng-model="classifiedsFilter">
</md-input-container>

<md-input-container>
    <label>Select a Master</label>
    <md-select ng-model="name">
        <md-option ng-repeat="name in names | orderBy: 'toString()'" value="{{ name }}">  
        {{ name }} 
        </md-option>
    </md-select>
</md-input-container>

<md-input-container>
    <md-button class="md-warn" ng-click="classifiedsFilter = ''; name = ''">Clear</md-button>
</md-input-container>

foll是视图中主要内容区域的代码:

<md-content class="md-padding" layout="row" layout-align="center" layout-wrap>
    <md-card ng-repeat="classified in classifieds track by $index | filter: classifiedsFilter | filter: name" flex-xs="100" flex-gt-sm="70">

    <md-card-content>
        <div class="classified-info">
            <h2 class="md-display-2">{{ classified.name }}</h2>
            <ul> 
                <li ng-repeat="thought in classified.thoughts track by $index">{{ thought }}</li>
            </ul>  
        </div>

        </md-card-content>
    </md-card>
</md-content>

foll是控制器:

(function(){
     "use strict";   
     angular
      .module("ngClassifieds")
      .controller("classifiedsCtrl", function($scope, $http, classifiedsFactory) {
        classifiedsFactory.getClassifieds().then(function(mastersdata) {   
            $scope.classifieds = mastersdata.data;
            $scope.names = getNames($scope.classifieds);
        });

        function getNames(classifieds) {    
            var names = [];
            angular.forEach(classifieds, function(item) {                                   
                        names.push(item.name);                  
            });

            return _.uniq(names);               
        }    
    });    
})();

任何帮助都将受到赞赏。谢谢。

0 个答案:

没有答案