0

我想生成类似于 facebook 墙类型效果的东西,并且每次创建帖子时都会更新墙。我已经建立了我希望 css/html 与 php 一起看的方式,但我现在想通过 ajax 来实现。

我的问题-它们是 jquery partials 这样的东西吗?就像一个视图,我可以推入我的 html 页面。由于我的更新声明已从

sel.prepend('<li id="'+response[i].post_id +'"> ' + response[i].title + '</li>');   

使用下面的 html 更新页面需要更多时间

帖子外观 imgs/t_silhouette.jpg"/> 用户名 title?> img_url?>'/>*/?> img_url?>"/> link?>">link_title?> link_caption?> message?> /imgs/cog. gif') no-repeat;margin-right:5px;">点赞·评论·3 月 7 日 19:08 通过 APPNAME
4

1 回答 1

3

你可以使用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);

工作小提琴

于 2012-06-01T11:35:11.957 回答