简体   繁体   English

更新骨架.js集合,而无需重新呈现模板

[英]Update backbone.js collection without re-rendering the template

Say I have five ranks, and different data points about each rank (salary, number, average, etc.). 假设我有五个等级,并且每个等级都有不同的数据点(薪水,数字,平均值等)。 I build a collection of models, one model for each rank. 我建立了一个模型集合,每个等级一个模型。

Then I have a Rank view and an App view - rendering down five Rank views inside my App view. 然后,我有一个Rank视图和一个App视图-在我的App视图中向下绘制五个Rank视图。 I also need to put a d3 chart inside each one of those rank views. 我还需要在每个排名视图中放置一个d3图表。

SO far, no problems. 到目前为止,没有问题。 But then I choose a button, update my collection with new data, and I have to re-render each Rank view to display the new data in my collection, correct? 但是,然后我选择一个按钮,用新数据更新我的收藏集,然后我必须重新渲染每个“等级”视图以在收藏夹中显示新数据,对吗? Re-rendering the data would rebuild the d3 chart each time, which I don't want to do, because I want the chart to have transitions. 每次重新渲染数据都会重建d3图表,这是我不想做的,因为我希望图表具有过渡。

Can anyone give me a little guidance? 谁能给我一点指导? Not code necessarily, just possible solutions? 不一定要编码,只是可能的解决方案?

You can simply update values and re-animate them at will. 您可以简单地更新值并随意重新设置它们的动画。 There's no need to fully destroy the object and create a new one, though that's a shortcut you see taken often because it is scary simple....but it also introduces display issues at the same time. 无需完全销毁该对象并创建一个新对象,尽管这是您经常看到的快捷方式,因为它很简单……。但是它同时也带来了显示问题。

Here's a simple example of changing values of a table and re-animating instead of destroying and making new: D3 redraw example You obviously get your data very differently via Backbone models, but the concepts are the same. 这是一个简单的示例,用于更改表的值并重新设置动画,而不是破坏和创建新的示例D3重绘示例您显然可以通过Backbone模型获得不同的数据,但是概念是相同的。

I have a similar pattern as you in my lighting control app, and I really have grown fond of using a grid to render the collection, with links to open each of the individual views, whether via a link to a new page (my preferred method) or a modal (the bosses' favorite method) My current grid of choice is Backgrid.js which is tied directly to the collection and therefore requires no work at all to update on model change. 我的照明控制应用程序中的模式与您相似,并且我真的很喜欢使用网格来渲染集合,并带有打开每个单独视图的链接,无论是通过链接到新页面(我的首选方法) )或模态(老板最喜欢的方法)。我当前选择的网格是Backgrid.js ,它直接与集合绑定,因此根本不需要任何工作来更新模型更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM