Javascript Jade、Express.js、NodeJS-使用新数据自动呈现UI

Javascript Jade、Express.js、NodeJS-使用新数据自动呈现UI,javascript,json,node.js,express,pug,Javascript,Json,Node.js,Express,Pug,JSON对象(故事)如下所示: [ { title: "Story of Learning NodeJS", id: "1", description: "Interesting, Fun, Exciting" }] ul each story in stories li span#storyTitle= story.title 用于渲染故事的JADE模

JSON对象(故事)如下所示:

    [ {
            title: "Story of Learning NodeJS",
            id: "1",
            description: "Interesting, Fun, Exciting" 
    }]
 ul
    each story in stories
        li
            span#storyTitle= story.title
用于渲染故事的JADE模板如下所示:

    [ {
            title: "Story of Learning NodeJS",
            id: "1",
            description: "Interesting, Fun, Exciting" 
    }]
 ul
    each story in stories
        li
            span#storyTitle= story.title
这将在客户端呈现故事列表。现在,我有了一个createstory功能,我将使用它添加一个新的故事,从而将它添加到JSON对象中。我希望在客户端UI中反映这一点,而不刷新页面

我试着使用:

response.render("index", {stories: stories });
在POST方法之后,将故事添加到故事对象。但渲染不会发生


如何做到这一点

您有几种可能性:

使用:

有一个很好的特性你可以使用,它叫。您可以轻松地绑定数据,当数据在后端发生更改时,前端也会发生更改。但你需要重写你的应用程序:(

使用jQuery:
这是一个小脚本,它使用
$.load
重新加载paga的一部分:

$.reloadSection = function (id) {
  var q = window.location.pathname + (window.location.search || "") + " " + id;
  $(id).load(q, function () {});
};
现在:


它很有效!

Awesome..reloadSection非常有效..谢谢@Vinz243。我还将探讨使用Meteor框架的可能性。:)