gpt4 book ai didi

javascript - Sencha touch 从 json 获取数据

转载 作者:行者123 更新时间:2023-11-28 19:55:22 25 4
gpt4 key购买 nike

最近我尝试使用sencha touch从json文件中获取数据,但它显示0结果,请引用下面的编码并告诉我我的错误,

谢谢

app.js

Ext.application({
name: 'TP',

views: [
'Main'
],

models: [
'User'
],

stores: [
'Users'
],

launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();

// Initialize the main view
Ext.Viewport.add(Ext.create('TP.view.Main'));

var user = Ext.create('TP.model.User', {
name: 'James Henry',
age: 24,
phone: '555-555-5555',
username: 'Admin'
});

Ext.getStore('Users').on('load', this.onStoreLoad, this);
console.log(Ext.getStore('Users'));
},

onStoreLoad: function(self, records, success, operation){
console.log(self);
}
});

模型::User.js

Ext.define('TP.model.User',{
extend: 'Ext.data.Model',

config: {
fields: [
{name: 'name', type: 'string'},
{name: 'age', type: 'int'},
{name: 'phone', type: 'string'},
{name: 'gender', type: 'string'},
{name: 'username', type: 'string'},
{name: 'alive', type: 'boolean', defaultValue: true}
],
validations: [
{type: 'presence', field: 'age'},
{type: 'length', field: 'name', min: 2},
{type: 'inclusion', field: 'gender', list: ['Male', 'Female']},
{type: 'exclusion', field: 'username', list: ['Admin', 'Operator']},
{type: 'format', field: 'username', matcher: /^[A-Za-z0-9 _]*$/ }
],
},

ageString: function(){
var age = this.get('age');
if(age > 1) {
return age + " yesrs old";
}else{
return age = " Yes old";
}
}
});

商店::Users.js

Ext.define('TP.store.Users', {
extend: 'Ext.data.Store',

config: {
model: 'TP.model.User',
autoload: true,
proxy: {
type: 'ajax',
url: 'http://localhost/sencha/SenchaStarter/data/users.json',
reader: {
rootProperty: 'users',
type: 'json'
}
}
}
});

JSON 文件 users.json

{
"users": [
{
"name": "Mike Henderson",
"age": 24,
"phone": "555-555-555",
"gender": "Male",
"username": "mhenderson",
"alive": true
},
{
"name": "Sally Michael",
"age": 34,
"phone": "555-555-555",
"gender": "Female",
"username": "sallym",
"alive": true
},
{
"name": "Rory Muldoon",
"age": 19,
"phone": "555-555-555",
"gender": "Male",
"username": "greatscott",
"alive": true
}
]
}

最佳答案

商店尚未加载,因为您尚未加载。原因是您在商店中编写此配置选项时出现拼写错误:

autoload

当需要时:

autoLoad

关于javascript - Sencha touch 从 json 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22681049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com