通过id-Extjs将数据加载到模型中

时间:2012-06-13 12:07:19

标签: javascript extjs extjs4

我试图在Extjs中使用直接存储 这是我商店的代码

Ext.define('IDE.store.Files', {
    extend: 'Ext.data.Store',
    proxy: {
        type: 'direct',
        api: {
            create:Files.AddNew,
            read:Files.GetFile,
            update:Files.Update,
            destroy:Files.Delete,
            //load:Files.GetFile
        },
        paramOrder:'Path'
    },
    model:'IDE.model.File'
})

模型的代码是

Ext.define('IDE.model.File', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'Path', type: 'string' },
        { name: 'Name', type: 'string' },
        { name: 'Extention', type: 'string' },
        { name: 'Content', type: 'string' }
    ],
    idProperty:'Path',
    store:'IDE.store.Files'
})

您可以看到idPropertyPath 以下代码段给出错误

//this.getStore('IDE.store.Files').load(path, { sucess: function (file) {
//                console.log(file.get('Content'));           
//            } });
this.getStore('IDE.store.Files').load(path);

这里我从某处获取path并尝试从特定路径加载文件 错误是

 Ext.data.proxy.Direct.doRequest(): No direct function specified for this proxy

现在问题是extjs的文档不够,我搜索到的任何地方我都只能看到api proxy对象中的4个api。 哪个是 1.创建
2.read
3.update
4.destroy

哪个api我错过了?或
我需要在哪里为load()

提供直接功能

1 个答案:

答案 0 :(得分:1)

我可以通过我的代码找出多个问题,所以只是在这里寻求社区的帮助 1.我调用加载函数的方式是正确的..它只是doest接受参数但是整个对象有范围和回调所以mayb这是错误的说法 http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-method-load
2.如果我只是删除api ..并使用directFn配置选项,那么它似乎可以工作..

<强>代码:

Ext.define('IDE.store.Files', {
    extend: 'Ext.data.Store',
    proxy: {
        type: 'direct',
        directFn: Files.GetFile, // <--- new line of code
        api: {
            create:Files.AddNew,
            //read:Files.GetFile, // <--- old line of code
            update:Files.Update,
            destroy:Files.Delete
        },
        paramOrder:'Path'
    },
    model:'IDE.model.File'
})
相关问题