[英]Filling static HTML page with JSON data
I am looking for a good template library that will allow me to fill in a static HTML page with a few variables that will be in JSON format - using javascript. 我正在寻找一个好的模板库,该模板库将允许我使用几个使用JSON格式的变量来填充静态HTML页面。 There will only be a few variables that change and one might be in
<title></title>
只有几个变量会发生变化,一个可能在
<title></title>
Ideally I'm looking for something like: 理想情况下,我正在寻找类似的东西:
<div>
Name: {name} is currently {age} years old
</div>
and then simply being able to supply the values for name and age via JSON and having it populated with values on the fly. 然后只需能够通过JSON提供名称和年龄的值,并即时填充值即可。
Does anyone know of a library that would work well? 有谁知道一个很好的图书馆?
Thanks in advance. 提前致谢。
Why noy just use jQuery? 为什么不使用jQuery?
http://jsfiddle.net/chace/NF496/7/ http://jsfiddle.net/chace/NF496/7/
var someJSONName = "Jimmy"
var someJSONAge = "32"
$("#myContent").click(function () {
$("#myContent").effect("highlight", 1500);
$("#myContent").text("Name: " + someJSONName + " is currently " + someJSONAge + " years old.");
});
Take a look at AngularJS too. 也来看看AngularJS。 Especially optimal if you're working with large datasets that can change over the lifetime of the page.
如果您正在处理可能在页面的整个生命周期内发生变化的大型数据集,则尤其适用。
Docs: http://angularjs.org/ 文件: http : //angularjs.org/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.