0

below you can see my Login functionality, which actually is working. But it does not load the provided json file by the server into JSON Store.

"console.log("Store before load",UserStore)" and "console.log("Store after load",UserStore)" shows exactly the same message, so i guess "UserStore.load(jsonRes)" is not working at all. I also tried "UserStore.loadData(jsonRes)" and "UserStore.loadRawData(jsonRes)" which both work neither (Error: Uncaught TypeError: Object[object Object] has no method 'loadDataRaw'). Could you please explain me how to fix that issue? Thanks a lot.

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.');   
    } 

},

The Json file provided look like this:

{msg: "OK", user: Object}

'user' itself looks like this: {"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":[]}

My Store is defined as follows:

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'
}
});

The corresponding model:

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'
        }
    ]
}
});

Example of a View:

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'
     },
4

2 回答 2

0

你应该试试

success: function (response) {

    var loginResponse = response.responseText;
    ....
}
于 2013-07-18T09:39:17.720 回答
0

关于您的问题的几个想法:

  • 您有一个publicList未在模型中声明的字段
  • store.load相反,它不接受模型的实例 - 它使用来自服务器的数据加载您的本地存储
  • store.loadData或者store.loadRawData是您要走的路,但是您提到的消息 (Uncaught TypeError: Object[object Object] has no method..) 表明您没有成功检索到 store 的实例。为此,您应该首先实例化商店,而不仅仅是声明它;使用Ext.create方法
  • 如果您loginResponse.user已经是 JSON 格式,则不应使用Ext.JSON.encode
于 2013-07-18T11:05:38.213 回答