Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当更新符合某些条件时,自动将子节点添加到ExtJS树面板的最佳方法是什么?_Extjs_Extjs4.1 - Fatal编程技术网

当更新符合某些条件时,自动将子节点添加到ExtJS树面板的最佳方法是什么?

当更新符合某些条件时,自动将子节点添加到ExtJS树面板的最佳方法是什么?,extjs,extjs4.1,Extjs,Extjs4.1,我正在使用ExtJS 4.1.1中的TreePanel/TreeStore,启用了自动同步,并通过Ajax代理定义了对服务器端点的API调用 当创建一个设置了某些属性的节点时,我让服务器在对创建API端点的自动同步调用期间自动添加两个子节点,服务器响应文本如下所示: { "success" : true, "errorMsg" : null, "children" : { "id" : "toolbox-42", "parentId" : null, "ite

我正在使用ExtJS 4.1.1中的TreePanel/TreeStore,启用了自动同步,并通过Ajax代理定义了对服务器端点的API调用

当创建一个设置了某些属性的节点时,我让服务器在对创建API端点的自动同步调用期间自动添加两个子节点,服务器响应文本如下所示:

{
  "success" : true,
  "errorMsg" : null,
  "children" : {
    "id" : "toolbox-42",
    "parentId" : null,
    "itemName" : "My Toolbox",
    "nodeType" : "toolbox",
    "children" : [{
        "id" : "tool-91",
        "parentId" : "toolbox-42",
        "itemName" : "Default Tool 1",
        "nodeType" : "tool",
        "leaf" : true,
      }, {
        "id" : "tool-92",
        "parentId" : "toolbox-42",
        "itemName" : "Default Tool 2",
        "nodeType" : "tool",
        "leaf" : true
      }
    ]
  }
}
var node = this.store.getNodeById(id);
if (node){
        this.store.load({node:node});
}
通过根级别的
“children”
键设置节点的属性就可以了。
“id”
属性在插入的节点上设置得很好

我的问题是服务器添加的子节点没有出现在树中。如何将这些添加到树视图中

以下是我考虑过的一些解决方案:

  • 在服务器响应中,将根级别的
    “children”
    对象放入数组中,并将新节点附加到数组的末尾(而不是将它们嵌套在其父节点下)。Ext.data.reader.reader(源)中的extractData方法指示将提取所有返回的记录。但是,Ext.data.Operation()中的commitRecords方法只更新请求中包含的clientRecords数量,这显然不包括服务器响应中出现的任何新记录
  • 服务器响应后,使用服务器响应中的
    “children”
    节点手动将记录添加到treestore客户端。但是,似乎没有简单的方法将这些记录标记为“已同步”
  • 根本不在服务器上添加记录;相反,在同步操作发生之前,在客户端上手动添加它们(因此,同步操作将给服务器3个插入操作)。但是,create请求中的子节点不会设置parentId,因为服务器尚未添加父节点并将id作为响应返回
  • 附加一个事件处理程序,该事件处理程序将在服务器添加父节点后触发一次,然后在客户端上以编程方式添加子节点(然后将自动同步到服务器)。但是,这需要两个服务器往返。此外,我所知道的唯一候选事件是Ext.data.TreeStore中的
    'write'
    ,并且没有相应的
    'failwrite'
    事件可用于在写入操作失败时删除侦听器。我可以添加一个抽象层来提供。。。但如果Sencha已经建立了更好的方法,我宁愿不要
还有其他建议吗?我将接受有效的建议或任何描述Sencha建议如何解决此问题的声明/链接

谢谢

更新:我的存储、代理和读卡器配置如下:

  var store = Ext.create('Ext.data.TreeStore', {
    model :    'App.models.Task',
    autoLoad : true,
    autoSync : true,
    proxy : {
      type : 'ajax',
      api : {
        create :  appUrl + 'Data/InsertTreeData',
        read :    appUrl + 'Data/GetTreeData',
        update :  appUrl + 'Data/UpdateTreeData',
        destroy : appUrl + 'Data/DeleteTreeData'
      },
      reader : {
        type : 'json',
        messageProperty : 'errorMsg'
      }
    }
  });

将节点添加到服务器端的树中时,我要做的是获取父对象id(可以是根,这很好),然后运行如下所示的refreshParent例程:

{
  "success" : true,
  "errorMsg" : null,
  "children" : {
    "id" : "toolbox-42",
    "parentId" : null,
    "itemName" : "My Toolbox",
    "nodeType" : "toolbox",
    "children" : [{
        "id" : "tool-91",
        "parentId" : "toolbox-42",
        "itemName" : "Default Tool 1",
        "nodeType" : "tool",
        "leaf" : true,
      }, {
        "id" : "tool-92",
        "parentId" : "toolbox-42",
        "itemName" : "Default Tool 2",
        "nodeType" : "tool",
        "leaf" : true
      }
    ]
  }
}
var node = this.store.getNodeById(id);
if (node){
        this.store.load({node:node});
}

这里的上下文是树面板。此例程将重新加载树的特定分支。

能否共享存储和读卡器的配置方式?@dbrin-请参阅我对该问题的更新。我可以问一下此代码是如何在客户端上启动的吗?存储上没有
'aftersync'
事件,只有在同步成功时才会触发
'write'
事件。我使用Ajax请求触发服务器端其他节点的创建。然后回调运行例程。我的问题是如何在自动同步更改的上下文中执行此操作。