Ext 4.2 Using proxy to save tree

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

when I use insertChild() or Sync(), proxy sends GET to server with just _dc param, what I should do to save my tree via proxy?

EDIT:added writer, now ext doing POST but with no data write listener also didn't call

Ext.define('App.model.FileTree', {     extend : 'Ext.data.Model',     fields : [          {name : 'id', type: 'string'},         {name : 'name', mapping:'name', type: 'string'},         {name : 'text', type: 'string'},      ] }); Ext.define('App.store.FileTree', {     extend: 'Ext.data.TreeStore',     alias:'filestore',     model : 'App.model.FileTree',     proxy: {         actionMethods: {             create: 'POST',             destroy: 'DELETE',             read: 'GET',             update: 'POST'         },         type: 'ajax',         url : '/app/store/FileTree.php',         reader: {             type: 'json'         },         writer: {             type: 'json',             nameProperty: 'mapping'         }     },     listeners : {         write: function(store, operation, opts){             Ext.each(operation.records, function(record){                 if (record.dirty) {                     record.commit();                 }             });         }     } }); 

trying add child like:

var tree = Ext.ComponentQuery.query('filetree')[0];  var record = tree.getSelectionModel().getSelection()[0];  record.appendChild({text:'test',name:'test',id:2,leaf:true});  tree.store.sync(); 

回答1:

Configure a writer inside the proxy. Without the writer proxy does not know what to do.

I have a tree in Ext 5.0 (but it works also in Ext 4.x) with tree model configured this way:

Ext.define('At.model.ContinentModel',{      extend:'Ext.data.TreeModel'     ,alias:'model.continentmodel'     ,idProperty:'id'     ,fields:[          {name:'text', type:'string', persist:true}         ,{name:'iconColor', type:'string'}     ]     ,proxy:{          type:'ajax'         ,url:'resources/service.php/tree/read/1/'         ,writer:{              type:'json'             ,allowSingle:false             ,encode:true             ,rootProperty:'data'         }     } }); 

The tree store is configured with autoSync:true. Changes in text field trigger server requests that look like this:



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!