1

私はyiiフレームワークを使用してExtJs4でWebサイトを開発しています。サーバーからExtjs4に返されたjsonデータにアクセスする方法に行き詰まっています。実際には、メッセージフィールドとjsonコードのすべてのフィールドを表示したいと思います。 ext js 4.ではどうすればよいですか?

これが私のjsonコードです(json形式のサーバー応答)

{

    "success": true,
    "data": [
        { 
            "msg": "uname and pass wrong"
        }
    ]

}

これが私のモデルクラスコードです

Ext.define('AM.model.Login',
        {
            extend:'Ext.data.Model',
            idProperty:'id',
            fields:['id','uname','pass'],
            proxy:
            {
                type:'ajax',
                url:'http://localhost/Balaee3/index.php?r=site/contact',

                reader:
                    {
                        type:'json',
                        root:'data',
                        successProperty:'success'
                    },//end of reader
                writer:
                    {
                        type:'json',
                        root:'records',
                        //writeAllFields:true
                    },//End of writer

            }//end of proxy
        }
);

ext js4のコントローラーファイルのjsonコードにアクセスするにはどうすればよいですか? ここでjsonデータを表示したいと思います。

            AM.model.Login.load(512, {
            params: {
            id: 512 
            },
            success: function(record, operation) {
            character = record; 
            },//end of success
            failure: function(record, operation) 
            {
            Ext.Msg.alert('Error', 'Failed to load model from the server.');
            },//end of failure
            callback: function(record, operation) {
                //Ext.Msg.alert('Success', 'Model loaded successfully.');
                console.log('Success', 'Model loaded successfully.');
                            }//end of call back function
            });

いくつかの提案をください

4

1 に答える 1

2

モデルにmessagePropertyを追加します。このようなことを試してください...

reader: {
        type: 'json',
        root: 'data',          
        successProperty : 'success',
        messageProperty : 'message',
        implicitIncludes: true
    }

コントローラ(サーバー)

 def message=''    
    def json = request.JSON       
    message=data.message
    def metaData = [ successProperty : 'success', messageProperty : 'message', totalProperty:'num', root:'data']
    def jsonData = [metaData:metaData, success:flag, message:message]
    render jsonData as JSON
于 2012-12-04T11:21:07.493 に答える