weixin_33737134 2010-11-24 13:56 采纳率: 0%
浏览 47

加载HTML而无需刷新

Im unsure of how to approach this, should I have the html to be loaded hidden or load it from somewhere? I want to load a form in one page, and dynamic content on other pages.

The form can be saved to mongo db, and when the page loads should load the data into that form from mongo db.

Where does the html live for all the pages? I want to have a clean html5 document with lets say a content div. all content goes into that block.

Server running Django Im want to use backbone.js for the app

any help would be appreciated

  • 写回答

1条回答 默认 最新

  • 撒拉嘿哟木头 2010-11-30 14:24
    关注

    The initial page should include the basic layout of the application (header, content, sidebar, different placeholder for your views, etc.)

    Then you load the application (usually with a controller) and render the different view that will replace the placeholders you had in your layout.

    To render the views, I suggest to use a templating engine. With backbone.js there is already underscore.js on the page, so you can use the templating engine included (http://documentcloud.github.com/underscore/#template). You then have to load the template on the page. The easiest way is to create include a script element on the page with your template inside:

    <script type="text/template" name="template1">
    your template here...
    </script>
    

    And you can load it using this:

    var template = _.template( jQuery("script[name=template1]").text() )
    

    and execute with your data

    var html = template(model)
    

    You build your page with different backbone views using different template.

    I hope that help!

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable