下面你可以看到我的登录功能,它实际上正在运行。但它不会将服务器提供的json文件加载到JSON Store中。
“console.log(”加载前存储“,UserStore)”和“console.log(”加载后存储“,UserStore)”显示完全相同的消息,所以我猜“UserStore.load(jsonRes)”是根本不工作。我也试过“UserStore.loadData(jsonRes)”和“UserStore.loadRawData(jsonRes)”,它们都不工作(错误:未捕获的TypeError:对象[对象对象]没有方法'loadDataRaw')。 你能解释一下如何解决这个问题吗?非常感谢。
Ext.util.JSONP.request({
url: 'http://127.0.0.1:4712/talentcommunity/getuserinfo',
headers: {
'content-type': 'application/x-www-form-urlencoded ; charset=utf-8'
},
method: 'post',
params: {
user:data1,
pw:data2
},
callbackName: 'myCallback',
success: function (response) {
var loginResponse = response;
if (loginResponse.msg == "OK") {
var UserStore = Ext.create('Ext.data.Store', {
model: 'Sabine.model.user',
data: response.user
});
me.signInSuccess();
}
else{
loginView.showSignInFailedMessage('token null.');
}
},
提供的Json文件如下所示:
{msg: "OK", user: Object}
'user'本身如下所示:{"token":"ee80d56688fb7d3a8bcf5939fc9cbcf1","title":"","login":"bmuster","facebookId":"","firstName":"Bertha","lastName":"Muster","nationality":"GM","birthDay":"12/09/82","phone":"+4989111111","mobile":"+4918111111","street":"Musterstra\ufffde 11","city":"Musterstadt","zipCode":"66666","willingToTravel":"","pictureUrl":"","eMail":"bmuster@example.com","publicList":[]}
我的商店定义如下:
Ext.define('Sabine.store.MyJsonPStore', {
extend: 'Ext.data.Store',
requires: [
'Sabine.model.user'
],
config: {
autoLoad: true,
autoSync: true,
clearOnPageLoad: false,
model: 'Sabine.model.user',
storeId: 'myStore'
}
});
相应的型号:
Ext.define('Sabine.model.user', {
extend: 'Ext.data.Model',
config: {
fields: [
{
name: 'token',
type: 'string'
},
{
name: 'title'
},
{
name: 'login'
},
{
name: 'facebookId'
},
{
name: 'firstName',
type: 'string'
},
{
name: 'lastName',
type: 'string'
},
{
name: 'nationality',
type: 'string'
},
{
name: 'birthDay',
type: 'string'
},
{
name: 'phone'
},
{
name: 'mobile'
},
{
name: 'street'
},
{
name: 'city',
type: 'string'
},
{
name: 'zipCode',
type: 'int'
},
{
name: 'willingToTravel'
},
{
name: 'pictureUrl'
},
{
name: 'eMail'
},
{
name: 'publicList'
}
]
}
});
视图示例:
Ext.define('Sabine.view.MeinAccount', {
extend: 'Ext.Container',
alias: 'widget.accview',
config: {
maxHeight: 480,
maxWidth: 320,
items: [{
xtype: 'tabpanel',
height: 430,
maxHeight: 480,
items: [
{
xtype: 'list',
title: 'Allgemein',
iconCls: 'home',
modal: false,
deferEmptyText: false,
itemTpl: [
'<table border = "0">',
'<tr>',
' <td>Firstname</td>',
' <td>{firstName}</td>',
' <td>Last<name/td>',
' <td>{lastName}</td>',
'</tr>',
'<tr>',
' <td>Nationality</td>',
' <td>{nationality}</td>',
'</tr>',
'</table>'
],
store: 'Sabine.store.UserStore'
},
答案 0 :(得分:0)
你应该试试
success: function (response) {
var loginResponse = response.responseText;
....
}
答案 1 :(得分:0)
关于你的问题的几点想法:
publicList
store.load
不接受模型的实例,相反 - 它使用服务器中的数据加载本地商店store.loadData
或store.loadRawData
是你要走的路,不过你提到的消息(Uncaught TypeError:Object [object Object]没有方法..)表示你没有成功检索到一个实例商店为了做到这一点,你应该首先实例化商店,而不仅仅是声明商店;使用Ext.create
方法loginResponse.user
已采用JSON格式,则不应使用Ext.JSON.encode