ExtJS4 Ext.data.Store 从函数加载数据
使用ExtJS4 Store,我想执行一个Javascript函数来返回json数据,即。 getMyJsonData,将数据加载到存储中。
function getMyJsonData() {
var myjson = {... };
return myjson;
}
浏览 doco,我找不到定义回调函数来加载数据的方法,我发现的只是一个加载已定义数据对象的内存存储。
我怎样才能调用一个函数呢?
Ext.define('perhoo.store.Users',
{
extend: 'Ext.data.Store',
model: 'perhoo.model.User',
autoLoad: true,
data : {
users: [
{ id: 1, name: 'joe44', email: '[email protected]'},
{ id: 2, name: 'bloggs44', email: '[email protected]'}
]
},
proxy: {
type: 'memory',
data: this.data,
reader: {
type : 'json',
root : 'users'
}
}
编辑
我想调用函数的原因是因为我想执行 LinkedIn API。 通过 Ext JSONP 代理(因为它是跨域)使事情变得复杂 10 倍,因为我必须获得 LinkedIn 身份验证等(我还不知道如何做到这一点),
即 var mydata = null;
function onLinkedInAuth() {
// Linked in api to find connections
IN.API.Connections("me").result( function(result) {
mydata = result;
} );
}
Using ExtJS4 Store, I want to execute a Javascript function to return json data, ie. getMyJsonData, to load the data into the store.
function getMyJsonData() {
var myjson = {... };
return myjson;
}
Trawling through the doco, I can't find a way to define a callback function to load the data, all I found was a Memory Store which loads an already defined data object.
How can I call a function instead ?
Ext.define('perhoo.store.Users',
{
extend: 'Ext.data.Store',
model: 'perhoo.model.User',
autoLoad: true,
data : {
users: [
{ id: 1, name: 'joe44', email: '[email protected]'},
{ id: 2, name: 'bloggs44', email: '[email protected]'}
]
},
proxy: {
type: 'memory',
data: this.data,
reader: {
type : 'json',
root : 'users'
}
}
EDIT
The reason I want to call a function is because I want to execute LinkedIn API.
And going through Ext JSONP Proxy (as it's cross domain) makes things 10x more complicated as I have to get LinkedIn auth etc etc (which I don't know how to do it yet)
i.e.
var mydata = null;
function onLinkedInAuth() {
// Linked in api to find connections
IN.API.Connections("me").result( function(result) {
mydata = result;
} );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ExtJS4的store使用代理加载数据,如下所示:
执行时,它从
url
、/users.json
读取数据,并存储到自身中。另外,如果您想自己处理数据并将它们加载到存储中,您可以检查以下内容:
并且您可以轻松地使用
setProxy
来更改您想要的行为。链接:
ExtJS4's store using proxy to load data, check below:
When executed, it reads data from the
url
,/users.json
, and store into itself.Also, if you want to process data yourself and load them into store yourself, you can check below:
And you could easily use
setProxy
to change the behavior when you want.Links: