我从服务器获取某种树数据(仅用于示例):
[
{
nodeName: "top level 1",
nodes: [
{
nodeName: "2nd level, item 1",
nodes: [
{
nodeName: "3rd level, item 1"}
]}
]},
{
nodeName: "top level 2",
nodes: [
{
nodeName: "2nd level, item 3",
nodes: [
{
nodeName: "3rd level, item 7"},
{
nodeName: "3rd level, item 8"},
{
nodeName: "3rd level, item 9"}
]}
]}
]
为了呈现这个,我正在使用 Backbone.Marionette.CollectionView 和 Backbone.Marionette.CompositeView http://jsfiddle.net/AdWjU/179/(在derickbailey 的文章之后)。
但我需要每 300 秒轮询一次服务器,它可以返回更改后的树:
[
{
nodeName: "top level 1",
nodes: [
{
nodeName: "2nd level, item 1",
nodes: [
{
nodeName: "3rd level, item 1"},
{
nodeName: "new name"} // changed
]}
]},
{
nodeName: "top level 2",
nodes: [
{
nodeName: "2nd level, item 3",
nodes: [
{
nodeName: "3rd level, item 7"},
{
nodeName: "3rd level, item 8"},
{
nodeName: "3rd level, item 9"},
{
nodeName: "3rd level, item 10"} // added
]}
]}
]
现在我只需调用 tree.update(data) 来重新渲染整个数据。
如何仅更新依赖于已更改属性的视图?
我正在尝试减少重新渲染的视图。我应该使用 CompositeViews 还是尝试使用 Backbone-relational 模型来完成这项任务?