Javascript 如何从外部api获取特定信息到我的ng repeat main.html
加载页面时,此部分按预期工作 我也需要在主控制器这些部分Javascript 如何从外部api获取特定信息到我的ng repeat main.html,javascript,angularjs,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Ng Repeat,加载页面时,此部分按预期工作 我也需要在主控制器这些部分 var onGetFilmData = function (data) { $scope.film = data; }; var onError = function (reason) { $scope.error = reason; }; imdb.getImdbInfo(-- need Id --).then(onGetFilmData, onError); 但我需要以某种方式放置每个post id,以便从Imdb ap
var onGetFilmData = function (data) {
$scope.film = data;
};
var onError = function (reason) {
$scope.error = reason;
};
imdb.getImdbInfo(-- need Id --).then(onGetFilmData, onError);
但我需要以某种方式放置每个post id,以便从Imdb api获取特定数据
Imdb.js
若我删除id部分并在getImdbInfo函数中放入一个特定的id字符串,main.html中的所有帖子都只填充一个电影信息。我想获取数据库中每部电影的数据(我持有数据库中每部电影的imdb id)。MainController
var jsonObj = {};
var refresh = function() {
$http.get('/myDatabase').success(function(response) {
jsonObj = response;
for(var i = 0; i < jsonObj.length ; i++){
jsonObj[i].title = '';
}
for(var i = 0; i < jsonObj.length ; i++){
(function(i) {
imdb.getImdbInfo(jsonObj[i].imdbId).then(function (data) {
jsonObj[i].title = data.Title;
});
})(i);
}
$scope.myBlogPosts = jsonObj;
});
};
refresh();
var jsonObj={};
var refresh=function(){
$http.get('/myDatabase').success(函数(响应){
jsonObj=响应;
对于(var i=0;i
main.html
<div class="row" ng-repeat="post in myBlogPosts.slice().reverse()">
<br>
<div class="col-md-9 text-center">
<a href="#/blog-post/{{post._id}}">
<div class="thumbnail mTextBg customShadow">
<br>
<img class="img-responsive" src="http://placekitten.com/700/400" alt="">
<div class="caption">
<h3>{{post.imdbId}}</h3>
<p>{{post.blogContent}}</p>
</div>
</div>
</a>
</div>
<div class="col-md-3">
<!-- Side Widget Well -->
<div class="well sideBars customShadow">
<h4 class="text-center">{{post.title}}</h4>
</div>
</div>
</div>
{{post.title}
我通过将来自Imdb的响应添加到来自数据库的json对象来解决问题。因此我可以轻松地在ng repeat中使用它们。MainController
var jsonObj = {};
var refresh = function() {
$http.get('/myDatabase').success(function(response) {
jsonObj = response;
for(var i = 0; i < jsonObj.length ; i++){
jsonObj[i].title = '';
}
for(var i = 0; i < jsonObj.length ; i++){
(function(i) {
imdb.getImdbInfo(jsonObj[i].imdbId).then(function (data) {
jsonObj[i].title = data.Title;
});
})(i);
}
$scope.myBlogPosts = jsonObj;
});
};
refresh();
var jsonObj={};
var refresh=function(){
$http.get('/myDatabase').success(函数(响应){
jsonObj=响应;
对于(var i=0;i
main.html
<div class="row" ng-repeat="post in myBlogPosts.slice().reverse()">
<br>
<div class="col-md-9 text-center">
<a href="#/blog-post/{{post._id}}">
<div class="thumbnail mTextBg customShadow">
<br>
<img class="img-responsive" src="http://placekitten.com/700/400" alt="">
<div class="caption">
<h3>{{post.imdbId}}</h3>
<p>{{post.blogContent}}</p>
</div>
</div>
</a>
</div>
<div class="col-md-3">
<!-- Side Widget Well -->
<div class="well sideBars customShadow">
<h4 class="text-center">{{post.title}}</h4>
</div>
</div>
</div>
{{post.title}
我通过将来自Imdb的响应添加到来自数据库的json对象来解决问题。因此,我可以轻松地在ng repeat中使用它们
<div class="row" ng-repeat="post in myBlogPosts.slice().reverse()">
<br>
<div class="col-md-9 text-center">
<a href="#/blog-post/{{post._id}}">
<div class="thumbnail mTextBg customShadow">
<br>
<img class="img-responsive" src="http://placekitten.com/700/400" alt="">
<div class="caption">
<h3>{{post.imdbId}}</h3>
<p>{{post.blogContent}}</p>
</div>
</div>
</a>
</div>
<div class="col-md-3">
<!-- Side Widget Well -->
<div class="well sideBars customShadow">
<h4 class="text-center">{{post.title}}</h4>
</div>
</div>
</div>