加载html而不刷新

发布于 2024-10-04 17:20:43 字数 259 浏览 0 评论 0原文

我不确定如何解决这个问题,我应该隐藏要加载的 html 还是从某个地方加载它?我想在一个页面上加载表单,并在其他页面上加载动态内容。

表单可以保存到 mongo db,当页面加载时应该将数据从 mongo db 加载到该表单中。

所有页面的 html 位于哪里?我想要一个干净的 html5 文档,其中包含一个内容 div。所有内容都进入该块。

运行 Django 的服务器 我想在应用程序中使用backbone.js,

任何帮助将不胜感激

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柳絮泡泡 2024-10-11 17:20:43

初始页面应包括应用程序的基本布局(标题、内容、侧边栏、视图的不同占位符等)。

然后加载应用程序(通常使用控制器)并呈现不同的视图,以替换您拥有的占位符在你的布局中。

为了渲染视图,我建议使用模板引擎。对于backbone.js,页面上已经有underscore.js,因此您可以使用包含的模板引擎(http://documentcloud.github.com/underscore/#template)。然后您必须在页面上加载模板。最简单的方法是在页面上创建包含模板的脚本元素:

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

您可以使用以下方法加载它:

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

并使用您的数据执行

var html = template(model)

您使用不同的模板使用不同的主干视图构建页面。

我希望有帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文