用于将json转换为html的简单jquery插件

Vai*_* Pc 5 html javascript php jquery json

我需要将此json数据附加到html元素.

[
    {
        "website":"google",
        "link":"http://google.com"
    },
    {
        "website":"facebook",
        "link":"http://fb.com"
    }
]
Run Code Online (Sandbox Code Playgroud)

如何使用任何插件轻松转换这个.目前,我在jquery中找不到任何简单的插件,所以请帮助我的朋友.

提前致谢..........

sha*_*eer 8

嗨,你可以使用jPut jQuery插件(http://plugins.jquery.com/jput/)

创建一个HTML jPut模板

<div jput="template">
  <a href="{{link}}">{{website}}</a>
</div>
<div id="main">
</div>

<script>
$(document).ready(function(){
var json=[{"website":"google","link":"http://google.com"},
    {"website":"facebook","link":"http://fb.com"}];

   $('#main').jPut({
       jsonData:json,   //your json data
       name:'template'  //jPut template name
   });
});
</script>
Run Code Online (Sandbox Code Playgroud)

  • 嗨,非常感谢,这正是我需要实现的.再次,非常感谢,这对我有用... (2认同)

Har*_*ier 5

与普通解析相比,jPut易于使用.如果要附加大量数据,则很难使用$ .each循环追加.在jPut中只需要创建模板并打印数据,只需将对象名称放在{{}}中即可.