Javascript 通过id Extjs将数据加载到模型中
我正在尝试使用Extjs中的直接存储Javascript 通过id Extjs将数据加载到模型中,javascript,extjs,extjs4,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,
这是我商店的密码
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'
})
如您所见,idProperty
是Path
以下代码段给出了错误消息
//this.getStore('IDE.store.Files').load(path, { sucess: function (file) {
// console.log(file.get('Content'));
// } });
this.getStore('IDE.store.Files').load(path);
这里我从某处获取路径
,并尝试从特定路径加载文件
错误是 Ext.data.proxy.Direct.doRequest(): No direct function specified for this proxy
现在的问题是,extjs的文档还不够,我搜索的每个地方都只能在proxy
的api
对象中看到4个api。
哪些是1.创建
2.阅读
3.更新
4.销毁
我遗漏了哪个api?或
我需要在哪里为
load()
提供一个直接函数?我可以用我的代码解决多个问题,所以只需在这里提供社区帮助。1.我调用load函数的方法是正确的。。它只接受参数,而是一个具有作用域和回调的整个对象,所以可能这就是错误
2.如果我只是删除
api
。。然后使用directFn
config选项,它似乎可以工作
代码:
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'
})
Ext.define('IDE.store.Files'{
扩展:“Ext.data.Store”,
代理:{
类型:'直接',
directFn:Files.GetFile,//您使用的是哪个版本的ExtJS?因为您为load()指定的参数似乎不正确。另外,可以从api中删除load:config:-它不受支持。ooops这是因为我在尝试一些东西。现在我编辑了这个问题以反映确切的情况EXT?4.0.7?4.1上的哪个版本?虽然我认为这是个问题,但我相信正确的load()参数应该是这样的:this.getStore('IDE.store.Files').load({params:{path:'somepath'})。你能确认这仍然不起作用吗?我认为这是因为ExtJS在模型中查找代理。非常确定你的代码可以与4.1一起使用。无论如何,你能尝试将代理定义移动到模型中,看看它是否起作用吗?我添加了代码,以便下一位读者可以看到代码的样子。