【发布时间】:2015-08-16 03:59:37
【问题描述】:
我有一个运行 k2 的 joomla 站点,并通过在字符串末尾添加 format=json 来从中提取信息:https://www.example.com/posts?format=json 输出如下内容:
{
site: {
url: "https://www.example.com",
name: "mySite"
},
category: {
id: "67",
name: "Gauteng",
alias: "gauteng",
link: "/tna/provincial/gauteng.html",
parent: "66",
extraFieldsGroup: "0",
image: null,
ordering: "1",
events: {
K2CategoryDisplay: ""
},
chidlren: []
},
items: [{
id="1",
title="The Title",
body="body content here..."
},
{
id="2",
title="The Title",
body="body content here..."
}
}
现在我正在为此创建一个服务,并且只想访问“项目”。
.factory('Posts', function($http) {
var posts = [];
return {
getPosts: function(){
return $http.get("https://www.example.com/posts?format=json").then(function(response){
posts = response;
return posts;
});
},
getPost: function(index){
return posts[index];
}
}
});
它似乎没有工作。有什么方法可以通过调用访问“项目”?
【问题讨论】:
-
posts = response.items? Object property accessors -
确实需要引用 items 属性
标签: javascript angularjs ionic-framework angularjs-factory angularjs-http