Ext 4.2使用代理保存树 [英] Ext 4.2 Using proxy to save tree

查看:120
本文介绍了Ext 4.2使用代理保存树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用insertChild()或Sync(),代理发送GET到服务器只有_dc参数,我应该做什么来保存我的树通过代理?

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?

编辑:添加的作者,现在ext做POST,但没有数据
写监听器也没有调用

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();
                }
            });
        }
    }
});

尝试添加孩子喜欢:

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();


推荐答案

配置 writer 。没有作者代理不知道该怎么做。

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

我在Ext 5.0中有一棵树(但它也在Ext 4.x中工作),树模式配置为:

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'
        }
    }
});

树存储配置为 autoSync:true text 中的更改字段触发服务器请求,如下所示:

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

这篇关于Ext 4.2使用代理保存树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆