【发布时间】:2016-11-24 02:53:48
【问题描述】:
我在加载我的第一个 ExtJS 商店时遇到问题。
var testStore = Ext.data.StoreManager.lookup('myUserStoreID');
testStore.load({
callback: function (records, operation, success) {
testStore.each(function (record) {
debugger;
var task = record.data.description;
console.log(task);
});
//debugger;
//var x2 = operation._response;
//var x3 = x2.responseText;
//var x4 = Ext.decode(x3);
////var x3 = Ext.JSON.decode(operation);
////var x2 = Ext.decode(operation.response);
//console.log(testStore);
}
});
如果我深入到 operation._response.responseText,我可以在调试器中看到正确的数据,但记录是空白的。所以我知道这与我的代码有关。如果我使用 Ext.decode 它确实返回一个对象。返回数据自动填充我的商店,我做错了什么。
这是我尝试使用的模型...我知道它还没有所有字段。
Ext.define('ExtApplication1.model.UserModel', {
extend: 'ExtApplication1.model.Base',
requires: ['ExtApplication1.model.Base'],
fields: [
/*
The fields for this model. This is an Array of Ext.data.field.Field definition objects or simply the field name.
If just a name is given, the field type defaults to auto. For example:
*/
{ name: 'UserID', type: 'int' },
{ name: 'UserName', type: 'string' },
{ name: 'password', type: 'string' },
{ name: 'Email', type: 'string' },
{ name: 'GroupID' }
],
proxy: {
type: 'ajax',
url: 'http://localhost:49537/api/user/gettargetuser/xxx/xxx',
reader: {
type: 'json',
rootProperty: 'JSON'
}
}
这是我创建商店的 MainModel.js
Ext.define('ExtApplication1.view.main.MainModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.main',
data: {
name: 'ExtApplication1',
appName: xxx,
appHeaderIcon: '<span class="fa fa-desktop fa-lg app-header-logo">',
footer: 'Copyright - xxx- x
},
stores: {
sessionListByInterest: {
model: 'MainMenuListModel',
autoLoad: false //was true
},
myUserStore: {
model: 'UserModel',
storeId: 'myUserStoreID',
autoLoad: false
},
【问题讨论】:
-
您的 JSON 属性名称与您的 extjs 模型中的字段名称不匹配。例如,您在 JSON 中有“电子邮件”,但模型中有“电子邮件”作为字段名称。如果你解决了这个问题,它会起作用吗?
-
@AmolKatdare 很奇怪,他们实际上匹配......至少电子邮件匹配。我为用户附上了 webapiClass 的图片...电子邮件确实显示为“电子邮件”。所以至少那个道具确实匹配。
-
这和我的 rootProperty 有关系吗?
-
另外,在我的 ExtJS 模型中,我是否必须具有在我的 webapi 中定义的导航属性...如您在上面看到的,我有公共虚拟组组,但我没有这在我的 EXTJS 模型中
-
请出示您的
myUserStoreID商店的代码。如果它派生自JsonStore,则默认情况下,商店有自己的代理,它总是优先于模型中定义的代理。