Backbone/Spine 中的常见模式是当发生某些情况时从头开始重新渲染整个视图。
但是,如果您只需要更新其中的一小部分(突出显示、选择、禁用、动画等),该怎么办?
重新渲染所有内容没有任何意义,因为它可能会破坏当前布局(例如,如果页面已滚动到某个点)。
另一方面,如果您使用诸如 $('.selected').highlight()
之类的内容从视图“内联”更新小部分,那么您将必须在视图中复制相同的逻辑< em>模板和 JavaScript 代码。
那么 Backbone/Spine 中的“最佳实践”是什么?
The common pattern in Backbone/Spine is to re-render the whole view from scratch when something happens.
But what do you do if you only need to update a small part of it (highlight, select, disable, animate etc)?
It doesn't make any sense to re-render everything as it might screw up the current layout (If the page has been scrolled to a certain point for example).
On the other hand if you update small parts "inline" from the View using something like $('.selected').highlight()
, then you would have to duplicate the same logic in the view template and JavaScript code.
So what is the "best practice" in Backbone/Spine to do that?
发布评论
评论(2)
在 Spine 中,使用元素模式:http://spinejs.com/docs/controller_patterns< /a>
In Spine, use the element pattern: http://spinejs.com/docs/controller_patterns
在房子的主干一侧,您最终会使用相同的 jquery...只是包裹在主干视图中。我在博客中提到了这一点,在这里:
http://lostechies.com/derickbailey/2011/09/26/seo-and-accessibility-with-html5-pushstate-part-2-progressive-enhancement-with-backbone-js/
在这种情况下忽略推送状态、搜索引擎优化和可访问性语言。渐进增强的想法正是您所追求的
on the backbone side of the house, you'd end up using the same jquery... just wrapped up in a backbone view. i blogged about this, here:
http://lostechies.com/derickbailey/2011/09/26/seo-and-accessibility-with-html5-pushstate-part-2-progressive-enhancement-with-backbone-js/
ignore the pushstate, seo and accessibility language in this case. the progressive enhancement ideas are what you're after