我想生成类似于 facebook 墙类型效果的东西,并且每次创建帖子时墙都会更新。我已经构建了我希望 css/html 如何使用 php 来查看,但我现在想通过 ajax 来完成。
我的问题 - 他们是 jquery 部分之类的东西吗?就像我可以推送到我的 html 页面中的 View 一样。因为我的更新声明已经从
sel.prepend('<li id="'+response[i].post_id +'"> ' + response[i].title + '</li>');
使用下面的 html,更新页面需要更多时间
发布后外观 imgs/t_silhouette.jpg"/> 用户名 标题?> img_url?>'/>*/?> img_url?>"/> 链接?>">link_title?> 链接标题?> 留言?> /imgs/cog.gif') no-repeat;margin-right:5px;"> 点赞·评论·3月7日19:08通过APPNAME最佳答案
您可以使用http://handlebarsjs.com/语法非常简单。您必须定义这样的模板
<script type="text/x-handlebars" id="people-template">
<ul>
{{#each people}}
<li >Name: {{name}} : Location: {{location.city}}</li>
{{/each}}
</ul>
</script>
然后你就可以像这样使用它
var context= {
people: [
{ name: "John Doe", location: { city: "Chicago" } },
{ name: "Jane Sinha", location: { city: "New York"} },
{ name: "Name Test", location: { city: "LA"} }
]
};
var template = Handlebars.compile($("#people-template").text());
var html = template(context);
$(document.body).html(html);
关于javascript - 使用 jquery 进行模板/部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10849287/