我有如下Ext模型定义Ext.define('UserModel', {
extend: 'Ext.data.Model',
idProperty: 'GUID',
fields: [
{ name: 'GUID', type: 'string' },
{ name: 'NickName', type: 'string' },
{ name: 'Name', type: 'string' },
{ name: 'Cellphone', type: 'string' },
{ name: 'UserName', type: 'string' },
{ name: 'Sex', type: 'string' },
{ name: 'Date', type: 'string' },
{ name: 'IsBaseUser', type: 'boolean' },
{ name: 'IndexUrl', type: 'string' },
{ name: 'AreaName', type: 'string' },
{ name: 'AreaId', type: 'string' },
{ name: 'Birthday', type: 'string' },
]
});Ext.define("ComInfoModel", {
extend: "Ext.data.Model",
idProperty: 'GUID',
fields: [
{ name: 'GUID', type: 'string' },
{ name: 'ComName', type: 'string' },
{ name: 'RegName', type: 'string' },
{ name: 'ComLogo', type: 'string' },
{ name: 'ComSite', type: 'string' },
{ name: 'ComUrl', type: 'string' },
{ name: 'ComEmail', type: 'boolean' },
{ name: 'ComPhone', type: 'string' },
{ name: 'BusinessTime', type: 'string' },
{ name: 'BusPath', type: 'string' },
{ name: 'ComLicenseNo', type: 'boolean' },
{ name: 'ComLicensePic', type: 'boolean' },
{ name: 'Legal', type: 'string' },
{ name: 'LegalIdCard', type: 'string' },
{ name: 'LegalPhone', type: 'string' },
{ name: 'AboutCom', type: 'string' },
{ name: 'PersonCount', type: 'string' },
{ name: 'AreaId', type: 'string' },
{ name: 'AreaName', type: 'string' },
{ name: 'ComAdderss', type: 'string' },
{ name: 'IndustryClassId', type: 'string' },
{ name: 'IndustryClassName', type: 'string' },
{ name: 'Products', type: 'string' },
{ name: 'UserAccountId', type: 'string' },
]
});
Ext.define("UserAccountModel", {
extend: "Ext.data.Model",
idProperty: 'GUID',
fields: [
{ name: 'GUID', type: 'string' },
{ name: 'Level', type: 'number' },
{ name: 'CertificationLevel', type: 'number' },
{ name: 'OrgType', type: 'number' },
{ name: 'Tags', type: 'string' }
],
hasMany: [
{ name: 'Header', model: 'UserModel' },
{ name: 'MainUser', model: 'UserModel' },
{ name: 'ComInfo', model: 'ComInfoModel' }
]
});可以看出:UserAccountModel模型有三个一对一关系,即:Header关联一个UserModel模型,MainUser 关联一个UserModel模型,ComInfo关联一个ComInfoModel模型。
我从服务端直接返回了如下格式的JSON数据(全部数据的一部分):{
"DataCount":30,
"Data":[{
"GUID":"f8efb990-f215-4da2-aa82-073071209c2a",
"Level":0,
"CertificationLevel":0,
"Header":null,
"MainUser":{
"GUID":"edfc6736-17e8-4006-86bb-ceaf3eeeb9f7",
"NickName":"",
"Name":null,
"Cellphone":null,
"UserName":"",
"TimeKey":"20110902113051609",
"Password":"",
"QuestionOne":null,
"QuestionTwo":null,
"QuestionThree":null,
"AnswerOne":null,
"AnswerTwo":null,
"AnswerThree":null,
"Sex":0,
"ImAccount":null,
"ImType":0,
"UserFace":null,
"AccountState":0,
"IsShow":true,
"Tags":null,
"Date":"\/Date(1314934251000)\/",
"IsBaseUser":true,
"IndexUrl":"dgjiecheng",
"Info":null,
"AreaId":"",
"AreaName":"",
"AreaDetail":null,
"RegisteredAreaId":null,
"RegisteredAreaName":null,
"Birthday":"\/Date(1314934251000)\/",
"WorkDate":"\/Date(1314934251000)\/"},
"OrgType":1,
"Tags":null
},
"ComInfo":{
"ComName":"",
"RegName":null,
"ComLogo":"b7c66e996b1346afb04fe8e6fbefa7a1_20110902.jpg",
"ComSite":"",
"ComUrl":"dgjiecheng",
"ComEmail":null,
"ComPhone":
"0769-21395765",
"BusinessTime":null,
"BusPath":null,
"ComLicenseNo":null,
"ComLicensePic":"e6b89ee74bc8441782dcbc4a06591fb8_20110902.jpg",
"Legal":"",
"LegalIdCard":null,
"LegalPhone":null,
"AboutCom":"",
"PersonCount":"50-150人",
"AreaId":"",
"AreaName":"",
"ComAdderss":null,
"IndustryClassId":"3091676d-bce9-4be0-aba4-430909680ba1",
"IndustryClassName":"",
"Products":null,
"UserAccountId":"f8efb990-f215-4da2-aa82-073071209c2a"
}
}
]}
Grid绑定方式如下:var AccountStore = new Ext.data.JsonStore({
autoDestroy: true,
storeId: 'AccountStore',
model: 'UserAccountModel',
autoLoad: true,
pageSize: 20,
proxy: {
type: 'ajax',
url: '/Account/GetList',
actionMethods: "POST",
reader: {
type: 'json',
root: 'Data',
totalProperty: 'DataCount'
}
}
});
var grid = Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: AccountStore,
selModel: Ext.create('Ext.selection.CheckboxModel'),
columns: [{
header: '类型',
dataIndex: 'OrgType',
}, {
header: '名称',
dataIndex: 'ComName'//问题在这里(您看到的这种方式无效),我如何绑定ComInfo中的ComName属性?
}
]
extend: 'Ext.data.Model',
idProperty: 'GUID',
fields: [
{ name: 'GUID', type: 'string' },
{ name: 'NickName', type: 'string' },
{ name: 'Name', type: 'string' },
{ name: 'Cellphone', type: 'string' },
{ name: 'UserName', type: 'string' },
{ name: 'Sex', type: 'string' },
{ name: 'Date', type: 'string' },
{ name: 'IsBaseUser', type: 'boolean' },
{ name: 'IndexUrl', type: 'string' },
{ name: 'AreaName', type: 'string' },
{ name: 'AreaId', type: 'string' },
{ name: 'Birthday', type: 'string' },
]
});Ext.define("ComInfoModel", {
extend: "Ext.data.Model",
idProperty: 'GUID',
fields: [
{ name: 'GUID', type: 'string' },
{ name: 'ComName', type: 'string' },
{ name: 'RegName', type: 'string' },
{ name: 'ComLogo', type: 'string' },
{ name: 'ComSite', type: 'string' },
{ name: 'ComUrl', type: 'string' },
{ name: 'ComEmail', type: 'boolean' },
{ name: 'ComPhone', type: 'string' },
{ name: 'BusinessTime', type: 'string' },
{ name: 'BusPath', type: 'string' },
{ name: 'ComLicenseNo', type: 'boolean' },
{ name: 'ComLicensePic', type: 'boolean' },
{ name: 'Legal', type: 'string' },
{ name: 'LegalIdCard', type: 'string' },
{ name: 'LegalPhone', type: 'string' },
{ name: 'AboutCom', type: 'string' },
{ name: 'PersonCount', type: 'string' },
{ name: 'AreaId', type: 'string' },
{ name: 'AreaName', type: 'string' },
{ name: 'ComAdderss', type: 'string' },
{ name: 'IndustryClassId', type: 'string' },
{ name: 'IndustryClassName', type: 'string' },
{ name: 'Products', type: 'string' },
{ name: 'UserAccountId', type: 'string' },
]
});
Ext.define("UserAccountModel", {
extend: "Ext.data.Model",
idProperty: 'GUID',
fields: [
{ name: 'GUID', type: 'string' },
{ name: 'Level', type: 'number' },
{ name: 'CertificationLevel', type: 'number' },
{ name: 'OrgType', type: 'number' },
{ name: 'Tags', type: 'string' }
],
hasMany: [
{ name: 'Header', model: 'UserModel' },
{ name: 'MainUser', model: 'UserModel' },
{ name: 'ComInfo', model: 'ComInfoModel' }
]
});可以看出:UserAccountModel模型有三个一对一关系,即:Header关联一个UserModel模型,MainUser 关联一个UserModel模型,ComInfo关联一个ComInfoModel模型。
我从服务端直接返回了如下格式的JSON数据(全部数据的一部分):{
"DataCount":30,
"Data":[{
"GUID":"f8efb990-f215-4da2-aa82-073071209c2a",
"Level":0,
"CertificationLevel":0,
"Header":null,
"MainUser":{
"GUID":"edfc6736-17e8-4006-86bb-ceaf3eeeb9f7",
"NickName":"",
"Name":null,
"Cellphone":null,
"UserName":"",
"TimeKey":"20110902113051609",
"Password":"",
"QuestionOne":null,
"QuestionTwo":null,
"QuestionThree":null,
"AnswerOne":null,
"AnswerTwo":null,
"AnswerThree":null,
"Sex":0,
"ImAccount":null,
"ImType":0,
"UserFace":null,
"AccountState":0,
"IsShow":true,
"Tags":null,
"Date":"\/Date(1314934251000)\/",
"IsBaseUser":true,
"IndexUrl":"dgjiecheng",
"Info":null,
"AreaId":"",
"AreaName":"",
"AreaDetail":null,
"RegisteredAreaId":null,
"RegisteredAreaName":null,
"Birthday":"\/Date(1314934251000)\/",
"WorkDate":"\/Date(1314934251000)\/"},
"OrgType":1,
"Tags":null
},
"ComInfo":{
"ComName":"",
"RegName":null,
"ComLogo":"b7c66e996b1346afb04fe8e6fbefa7a1_20110902.jpg",
"ComSite":"",
"ComUrl":"dgjiecheng",
"ComEmail":null,
"ComPhone":
"0769-21395765",
"BusinessTime":null,
"BusPath":null,
"ComLicenseNo":null,
"ComLicensePic":"e6b89ee74bc8441782dcbc4a06591fb8_20110902.jpg",
"Legal":"",
"LegalIdCard":null,
"LegalPhone":null,
"AboutCom":"",
"PersonCount":"50-150人",
"AreaId":"",
"AreaName":"",
"ComAdderss":null,
"IndustryClassId":"3091676d-bce9-4be0-aba4-430909680ba1",
"IndustryClassName":"",
"Products":null,
"UserAccountId":"f8efb990-f215-4da2-aa82-073071209c2a"
}
}
]}
Grid绑定方式如下:var AccountStore = new Ext.data.JsonStore({
autoDestroy: true,
storeId: 'AccountStore',
model: 'UserAccountModel',
autoLoad: true,
pageSize: 20,
proxy: {
type: 'ajax',
url: '/Account/GetList',
actionMethods: "POST",
reader: {
type: 'json',
root: 'Data',
totalProperty: 'DataCount'
}
}
});
var grid = Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: AccountStore,
selModel: Ext.create('Ext.selection.CheckboxModel'),
columns: [{
header: '类型',
dataIndex: 'OrgType',
}, {
header: '名称',
dataIndex: 'ComName'//问题在这里(您看到的这种方式无效),我如何绑定ComInfo中的ComName属性?
}
]
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货