【发布时间】:2015-08-14 05:19:31
【问题描述】:
我从一个控制器移动了几个编队,我想使用“ng if”来比较id,但它不起作用。
代码如下:
var postsApi = 'http://mywebsite.com/wp-json/posts?filter[posts_per_page]=4&_jsonp=JSON_CALLBACK';
$http.jsonp( postsApi ).
success(function (data, status, headers, config) {
$scope.posts = data;
console.log( data );
}).
error(function(data, status, headers, config) {
console.log( 'Post load error.' );
});
var newsApi = 'http://mywebsite.com/wp-json/posts?filter[category_name]=news&filter[posts_per_page]=4&_jsonp=JSON_CALLBACK';
// This should go in a service so we can reuse it
$http.jsonp(newsApi).
success(function (data, status, headers, config) {
$scope.news = data;
console.log(data);
});
var jworldApi = 'http://mywebsite.com/wp-json/posts?filter[category_name]=world&filter[posts_per_page]=4&_jsonp=JSON_CALLBACK';
// This should go in a service so we can reuse it
$http.jsonp(jworldApi).
success(function (data, status, headers, config) {
$scope.jworld = data;
console.log(data);
});
在视图中:
<div class="highlight-topright">
<ion-item class="main_post" ng-repeat="post in posts" ng-if="$index == 0" href="#/kikarnews/posts/{{post.ID}}">
<div class="wrapper">
<img class="full-image" src="{{ post.featured_image.attachment_meta.sizes.medium.url }}" />
<h3 class="cat_name_main"> {{post.terms.category[0].name}}</h3>
</div>
<h2 ng-bind-html="post.title"></h2>
</ion-item>
<ion-item ng-repeat="post in posts" ng-if="$index != 0" href="#/mysite/posts/{{post.ID}}">
<div class="row main_home">
<div class="col col-50 main_img_home">
<img class="full-image" src="{{ post.featured_image.attachment_meta.sizes.medium.url }}">
</div>
<div class="col col-50 main_title_home">
<h5>{{ post.date }}</h5>
<h2 ng-bind-html="post.title"></h2>
</div>
</div>
</ion-item>
</div>
<!---news-->
<div class="news_mideel_home">
<h2>news</h2>
<ion-item ng-repeat="newsi in news" **ng-if="newsi.ID != post.ID**" href="#/mysite/posts/{{newsi.ID}}">
<div class="row main_home">
<div class="col col-50 main_img_home">
<img class="full-image" src="{{ newsi.featured_image.attachment_meta.sizes.medium.url }}">
</div>
<div class="col col-50 main_title_home">
<h5>{{ newsi.date }}</h5>
<h2 ng-bind-html="newsi.title"></h2>
</div>
</div>
</ion-item>
</div>
<div class="jworld">
<h2>jworld</h2>
<div ng-repeat="jworldi in jworld">
<ion-item ng-if="jworldi.ID == 5358" href="#/mysite/posts/{{jworldi.ID}}">
<div class="row main_home">
<div class="col col-50 main_img_home">
<img class="full-image" src="{{jworldi.featured_image.attachment_meta.sizes.medium.url }}">
</div>
<div class="col col-50 main_title_home">
<h5>{{ jworldi.date }}</h5>
<h2 ng-bind-html="jworldi.title"></h2>
</div>
</div>
</ion-item>
</div>
</div>
【问题讨论】:
-
尝试创建一个plunker / fiddle而不是让你的问题变得很大。
-
代码的输出是什么?
标签: javascript jquery json angularjs wordpress