【发布时间】:2014-08-01 12:31:15
【问题描述】:
我正在尝试从 Json 数据中获取数据,但它对我不起作用。我不确定我做错了什么。
Angular Ajax API 调用:
<script>
function PostsCtrlAjax($scope, $http) {
$http({
method: 'POST',
url: 'js/posts.json'
}).success(function(data) {
$scope.posts = data.deals;; // response data
});
}
</script>
HTML 数据绑定
<div id="ng-app" ng-app ng-controller="PostsCtrlAjax">
<div ng-repeat="post in posts">
<h2>
<a href='{{post.url}}'>{{post.title}}</a>
</h2>
<div class='time'>{{post.time}} - {{post.author}}</div>
<p>{{post.description}}</p>
<img ng-src="{{post.banner}}" />
</div>
</div>
Posts.json:
{
"result":"SUCCESS",
"resultMessage":"",
"deals":[
{
"title":"Multiple Ajax Image Upload without Refreshing Page using Jquery.",
"url":"http://www.9lessons.info/2013/08/multiple-ajax-image-upload-refreshing.html",
"banner":"https://lh5.googleusercontent.com/-VWIAbbjR1QM/Uf_v9v9LCbI/AAAAAAAAIAo/4ZhYhP3lcCg/s550/multiple.jpg",
"description":"Today I am presenting the most important social networking feature called multiple ajax image upload without refreshing the page using jquery and PHP. We just modified few lines of code in jqery.form.js plugin and renamed that to jquery.wallform.js. This feature is one of the key feature in Wall Script sale, big thanks to Arun Sekar for this code trick.",
"time":"Tuesday, August 6, 2013",
"author":"Srinivas Tamada"
},
{
"title":"Wall Script 6.0",
"url":"http://www.9lessons.info/2013/07/wall-script.html",
"banner":"https://lh5.googleusercontent.com/-ErPa0tEQgLs/UfZzaQ3NcFI/AAAAAAAAH7o/h_KH8Rf4AXs/s550/WallBanner.jpg",
"description":"Introducing the brand new Wall Script 6.0 with enrich social network features. Exactly year later I did released Wall Script previous version, it got awesome response and outstanding sale. This script IDEA was came out from my imagination, introducing powerful features like Conversations, OEmebd URL expanding system, Like/Share and Multiple image slider.",
"time":"MONDAY, JULY 29, 2013",
"author":"Srinivas Tamada"
}
],
"total":1207
}
我想从 json 文件标题、url、横幅等中获取。但我没有从我的 json 文件中获取任何数据。我该怎么做?
【问题讨论】:
-
我编辑了它们,没关系。我的 json 像这样开始“交易”:[我不知道我怎么能得到它。
-
data.deals?...但是我正在使用我的读心能力,所以如果没有看到代码,我可能会错。 -
更新了我的代码和问题
-
您是否费心调试您的代码并在您的
$http成功函数中查看data的值?
标签: json angularjs angularjs-scope