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

我的问题-他们是jquery局部对象吗?就像一个视图,我可以推入我的html页面。由于我的更新声明已经从

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


在下面的我的html中,更新页面需要花费更多时间


            后期外观
            
                imgs / t_silhouette.jpg“ />
                
                    用户名
                    标题?
                    
                        img_url?>'/> * /?>
                        img_url?>“ />
                    
                    

                        链接?>“>链接标题?>
                        link_caption?>
                        讯息?
                    
                    
                    
                    /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);


Working Fiddle

关于javascript - jQuery的模板/部分?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10849287/

10-12 03:37
查看更多