0
votes

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
first do insertChild and then use the sync method, as sync will only synchronize the newly added or updated or deleted records in the store.Deepak Patil
var tree = Ext.ComponentQuery.query('filetree')[0]; var root = tree.getRootNode() var store = tree.getStore('FileTree'); root.appendChild({text:'text',leaf:false,parentId:'40'}); store.sync(); all that I got on server side its 2 GETs with _dc, server returns json with success=true on it, no PUTs or POSTsuser840250
root.insertChild(1,{text:'text',leaf:false,parentId:'40'}); also didn't works. child adding localy but proxy wont push it to serveruser840250

1 Answers

0
votes

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:

Server request