ExtJs-如何使用ExtJs和Ext.Ajax.request方法加载json文件?
我希望使用extjs加载一个json文件。之前,我在jquery库的帮助下加载json文件,如下所示:ExtJs-如何使用ExtJs和Ext.Ajax.request方法加载json文件?,ajax,json,model-view-controller,extjs,Ajax,Json,Model View Controller,Extjs,我希望使用extjs加载一个json文件。之前,我在jquery库的帮助下加载json文件,如下所示: Ext.define('app.store.Students', { extend: 'Ext.data.Store', model: 'app.model.Student', storeId: 'StudentData', autoLoad: true, proxy: { type: 'ajax', url: 'data
Ext.define('app.store.Students', {
extend: 'Ext.data.Store',
model: 'app.model.Student',
storeId: 'StudentData',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'data/users.json',
success: function(resp) {
console.log(resp.responseText);
},
reader: {
type: 'json',
root: 'student1',
model: 'app.model.Student',
successProperty: 'success'
}
}
});
但是现在我想使用ExtJs加载我的json文件。我尝试了以下代码:
Ext.define('app.store.Students', {
extend: 'Ext.data.Store',
model: 'app.model.Student',
storeId: 'StudentData',
autoLoad: true,
});
Ext.Ajax.request({
url: 'data/users.json',
//method: 'GET',
success: function(response){
var text = response.responseText;
alert('1')
console.log(this.url);
// process server response here
}
});
但它说“uncaughtypeerror:无法调用undefined的方法”indexOf“。在firebug中检查时,下面给出的url在ext-all-debug.js中未定义
urlAppend : function(url, string) {
if (!Ext.isEmpty(string)) {
return url + (url.indexOf('?') === -1 ? '?' : '&') + string;
}
return url;
},
我试图在Ext.Ajax.request方法中控制上面给出的url,它说url未定义。我哪里做错了
仅供参考:这是我的文件结构:
-html file
-data folder - users.json
-app folder - store folder - js file (This is where I use my Ext.Ajax.request method)
我在相对路径上出错了吗?如果是,我应该如何使用它?如果未指定数据,并且如果自动加载为真或对象,创建后会自动调用此存储区的加载方法。请将自动加载设置为false,或者使用带有ajax和reader的代理,然后使用回调函数来处理json数据 更新:试试这个
如果未指定数据,并且如果autoLoad为true或对象,则创建后会自动调用此存储的加载方法。可以将autoLoad设置为false或使用proxy并键入ajax和reader,然后使用回调函数来处理json数据 更新:试试这个
我尝试将自动加载设置为false。我没有得到错误'UncaughtTypeError:无法再调用undefined'的方法'indexOf'。但是,我仍然无法在我的页面中加载数据。我的意思是url是错误的。我使用的是我的相对路径:“url:'data/users.json',”。这是错误的吗?结构应该是:app folder->stores,data folder,models,views,我的意思是以上所有内容都应该在你的app folder中。现在我已经将数据、模型、视图、store、controller放置在我的app folder中,并使用了“url:”app/data/users.json,但我的网格仍然没有加载数据:(并且console.log(this.url)仍然未定义:(我尝试将autoLoad设置为false。我没有收到错误“Uncaught TypeError:无法再调用undefined”的方法“indexOf”。但是,我仍然无法在我的页面中加载数据。我的意思是url错误。我使用的是我的相对路径:“url:”data/users.json“。这是错误的吗?结构应该是:app folder->stores,data folder,模型、视图我的意思是以上所有内容都应该放在你的应用程序文件夹中。现在我已经将数据、模型、视图、存储、控制器放在我的应用程序文件夹中,并使用了“url:”app/data/users.json“,但我的网格仍然没有加载数据:(并且console.log(this.url)仍然没有定义。)(
Ext.define('app.store.Students', {
extend: 'Ext.data.Store',
model: 'app.model.Student',
storeId: 'StudentData',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'app/data/users.json',
reader:{
type: 'json',
root: 'student1'//If you are using student1 as root.
}
}