2016-03-01 80 views
0

我的JavaScript是:NG表未呈现,行

$scope.questionsTable = new NgTableParams({}, { 
    getData: function($defer, params) { 
    return $http.get("/api/questions", { 
     params: searchParams 
    }).then(function(response) { 
     params.settings({ 
     total: response.data.count 
     }); 
     console.log(response.data.questions); 
     return $defer.resolve(response.data.questions); 
    }); 
    } 
}); 

而且response.data.questions绝对是一个数组。在我看来,我有

<table class="bordered striped highlight" ng-table="questionsTable"> 
    <tr ng-repeat="question in $data"> 
     <td class="top-td"> 
     <a href="#" ng-click="loadQuestionModal(question.id)"> 
      {{ question.id }} 
     </a> 
     </td> 
     <td class="top-td"> 
     <h6 markdown-to-html="question.Instruction.instructionText"></h6> 
     <blockquote ng-show="k8englishSubject" markdown-to-html="question.questionText"></blockquote> 
     <blockquote markdown-to-html="question.questionText" mathjax-bind="question.questionText" ng-show="k8mathSubject"></blockquote> 
     </td> 
     <td class="top-td"><ng-include src="'/views/partials/answerList.html'"></ng-include></td> 
     <td class="top-td" ng-show="k8englishSubject"> 
     <a ui-sref="passages.upsert({passageId: question.PassageId})" ng-show="question.PassageId"> 
      {{ question.Passage.passageTitle }} 
     </a> 
     </td> 
     <td class="top-td">{{ question.level }}</td> 
    </tr> 
</table> 

但是,我的表没有行正在呈现。我究竟做错了什么?

+0

http://www.codelord.net/2015/09/24/$q-dot-defer-youre-doing-it-wrong/ –

+0

问题是,您正在使用请求异步的承诺,您的表格已经在promise完成时呈现并且您的html不会被刷新。 –

+0

看看这里http://stackoverflow.com/questions/23325994/ng-table-not-working-for-dynamic-data/25381507#25381507 –

回答

0

原来我只是需要做

$scope.questionsTable = new NgTableParams({}, { 
    getData: function($defer, params) { 
    return $http.get("/api/questions", { 
     params: searchParams 
    }).then(function(response) { 
     params.settings({ 
     total: response.data.count 
     }); 
     console.log(response.data.questions); 
     return response.data.questions; 
    }); 
    } 
}); 

由于$http已经返回一个承诺。