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

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

问题描述

当我使用 insertChild() 或 Sync() 时,代理仅使用 _dc 参数将 GET 发送到服务器,我应该怎么做才能通过代理保存我的树?

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?

添加了作家,现在进行 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天全站免登陆