我正在使用angularJS + cordova进行移动应用。我能够显示列表视图,因为我在单击该项目时尝试更新列表项,值正在更改但UI未更新。 这是我的代码。
<md-list post class="" role="list" >
<md-item class="card" ng-repeat="post in posts">
<div class="card-header">
<div class="pro-pic">
<img src="{{post.UserImage}}" />
</div>
<h2>{{ post.UserName }}
<span>{{ post.CreatedDate | date:'medium' }} via --</span>
</h2>
<div class="post-info">{{ post.Description }}</div>
</div>
<div class="card-body">
<div class="card-img" ng-hide="post.IdeaImagePost == 0">
<img src="{{ post.IdeaImagePost }}" />
</div>
</div>
<div class="card-footer">
<div id="likeID" ng-click="onLike(post)"><i class="fa fa-thumbs-up {{post.LikeUserStatus ? 'active' : ''}}"></i><label> Like</label><span class="badge badge-xs badge-pink">{{ post.LikeUsersCount }}</span></div>
<div><i class="fa fa-commenting"></i> Comment<span class="badge badge-xs badge-pink">{{ post.CommentsCount }}</span></div>
</div>
</md-item>
</md-list>
查看更多
这是JS代码
$scope.onLike = function(post) {
console.log("LikeUserStatus: " + post.LikeUserStatus);
post.LikeUserStatus = !post.LikeUserStatus;
post.LikeUsersCount = post.LikeUserStatus ? parseInt(post.LikeUsersCount)+1 : parseInt(post.LikeUsersCount)-1;
console.log("LikeUserStatus: " + post.LikeUserStatus);
};
答案 0 :(得分:0)
console.log("LikeUserStatus: " + post.LikeUserStatus);
` $timeout(function(){
post.LikeUserStatus = !post.LikeUserStatus;
post.LikeUsersCount = post.LikeUserStatus ? parseInt(post.LikeUsersCount)+1 :parseInt(post.LikeUsersCount)-1
})`;
$ timeout在执行后运行摘要周期