我正在学习AngularJS并退出有关以JSON格式存储数据的信息。 我正在构建一个真正的应用程序来学习一个真正的项目。JSON存储HTML
这是一本在线杂志。现在我将所有文章基本数据存储在articles.json中。这样我可以将所有基本文章数据推送到主页。
[
{
"id":"1",
"category": "Activity",
"title": "Title goes here",
"short_desc": "Short description goes here",
"images": [
"img/article-img.jpg"
]
},
{
"id":"1",
"category": "Activity",
"title": "Title goes here",
"short_desc": "Short description goes here",
"images": [
"img/article-img.jpg"
]
}, ...
]
然后根据文章ID将用户引导到一个新的模板并加载与URL文章相关的JSON文件:article1.json。它看起来像这样。
{
"id":"1",
"category": "Activity",
"title": "Title goes here",
"html_desc": "<h1>Article subtitle goes here<h1><p>Paragraph text<\p>",
"images": [
"img/featured-img.jpg"
]
}
当然,我碰到的问题,在JSON,我不能,很容易使用HTML标签或即使我能,这将是文章的段落和标题转换成JSON格式的噩梦。
请指导我采取最佳做法。我假设我正在尝试处理数据的方式中缺少一些关键部分。也许我应该使用一些数据库来存储数据,而不是JSON。
请指教使用基于JS的框架如AngularJS和数据存储的最佳实践。
你能提供一个plnkr吗? – 2014-09-11 12:47:29