Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
安格拉斯。用JSON构建博客文章的最佳实践_Json_Angularjs - Fatal编程技术网

安格拉斯。用JSON构建博客文章的最佳实践

安格拉斯。用JSON构建博客文章的最佳实践,json,angularjs,Json,Angularjs,现在我有2个JSON文件负责文章内容。一个用于保存所有文章,以便在主页上发布。articles.json [ { "id":"1", "category": "books", "title": "Article title here", "short_desc": "Short desc here, maybe a bit longer", "images": [ "img/article-img1.jpg" ] , "fe

现在我有2个JSON文件负责文章内容。一个用于保存所有文章,以便在主页上发布。articles.json

[
{
    "id":"1",
    "category": "books",
    "title": "Article title here",
    "short_desc": "Short desc here, maybe a bit longer",
    "images": [
        "img/article-img1.jpg"
    ] ,
    "featured_stat":true,
    "featured_img": [
        "img/featured-img-1.jpg"
    ]
}
]
然后,我使用以下构造基于URL获取特定文章的文章详细信息:

app.controller('ArticleCtrl', ['$scope', '$routeParams', '$http',
function($scope, $routeParams, $http) {
    $http.get('pages/articles/' + $routeParams.articleId + '.json')
        .success(function(data) {
            $scope.article = data;
        });

}]);
1.json文章文件如下所示

 {
"id":"1",
"category": "Books & Magazines",
"title": "Title here",
"html_desc": "<p>Article content here</p>",
"images": [
    "img/featured-img-1.jpg"
]
{
“id”:“1”,
“类别”:“书籍和杂志”,
“标题”:“此处标题”,
“html_desc”:“此处的文章内容

”, “图像”:[ “img/featured-img-1.jpg” ]
}

因此,如果URL为/article/1,它将从articles文件夹中查找1.json文件。现在我认为最好将这些json文件合并成一个文件,并将所有文章信息保存在一个地方。这是一个好主意吗?如何在代码中基于URL检查要加载的文章,如何构造这个更大的JSON?我将有大约30篇文章


还有一个附带的问题,有没有办法编辑或向这个JSON添加新文章?

如果不使用服务器语言,就无法编辑静态文件。您没有任何服务器端存储吗?如果你不看看提供JavaScriptAPI的众多免费云存储服务中的一个,你可以共享一个链接,在这里我可以了解更多关于服务器端JS API的信息。例如,有很多