gpt4 book ai didi

javascript - Backbone 建议在服务器端生成页面时插入所有模型

转载 作者:行者123 更新时间:2023-11-29 10:37:37 25 4
gpt4 key购买 nike

我是一个有骨气的菜鸟。在 Addy Osmani's Book: 之后遇到了这个建议

有人可以帮我理解这个吗?如果服务器将模型作为页面生成的一部分进行推送(比如通过 JSP ),模型数据如何以 backbone model 结束?在客户端?

我可以通过 <% %> 理解 HTML 模板和数据的动态插入来自服务器的标签,但如何设置 backbone model ?除非它是从客户端本身获取的?

以下是本书的节选:

The Backbone documentation recommends inserting all models when the page is generated on the server side, rather than fetching them from the client side once the page is loaded. Since this chapter is trying to give you a more complete picture of how to communicate with a server, we will go ahead and ignore that recommendation.

最佳答案

请忽略该段。

我已经开发主干应用程序一年多了,还没有在文档中看到过这样的事情,也没有遇到过这样的场景。

Backbone.js docs开始于:

Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface (emphasis mine).

进一步quotes :

A Model manages an internal table of data attributes, and triggers "change" events when any of its data is modified. Models handle syncing data with a persistence layer — usually a REST API with a backing database.

API-integration进一步:

Backbone is pre-configured to sync with a RESTful API.

不,Backbone 文档并不特别推荐在服务器端处理 HTML 和插入所有模型。

如果你看看 router 的方式是设计的,您会看到它主要是为基于散列更改的 SPA(单一页面应用程序)设计的。

好吧,当我们谈论混合应用程序时,根本没有来自服务器的 html。

所以不用担心忽略那个评论:)。

关于javascript - Backbone 建议在服务器端生成页面时插入所有模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34272299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com