1

私はextjs4MVC構造で作業しており、extjs4ですべてのフィールドがサーバー側に送信されているという問題に直面していますが、モデルクラスの一部のフィールドのみをサーバー側に送信したいと思います。この出力を取得するにはどうすればよいですか?

1)これが私のモデルクラスです

Ext.define('ab.model.sn.UserModel',{
    extend: 'Ext.data.Model',
    //idproperty:'userId',//fields property first position pk. 
    fields: ['userId','firstName','middleName','lastName','languageId','primaryEmail','birthDate','password','securityQuestionId','securityQuestionAnswer','isMale','creationTime','ipAddress','confirmationCode','userStatusId',],
    proxy:
    {
        type:'ajax',
            //type:'localstorage',
            //id:'users',
        api:
        {
            read:'http://localhost/balaee/Balaee/index.php/SocialNetworking/user/AuthenticateLogin',
            create:'http://localhost/balaee/Balaee/index.php/SocialNetworking/user/AuthenticateLogin122',
            update:'http://localhost/balaee/Balaee/index.php/SocialNetworking/user/AuthenticateLogin123'
        },//end of api
        reader:
        {
            type:'json',
        },//end of reader
        writer:
        {
            type:'json',
            root:'records',
        },//End of writer

    }//end of proxy
});

2)これが私のコントローラーファイルコードです

var userObject = Ext.ModelManager.create(
        {
            firstName:record.get('firstName'),
            password:record.get('password'),

        },'ab.model.sn.UserModel');


userObject.save({    
    success: function(record, operation) 
    {
        console.log("registration successssssssssss  "+record.get('userId'));
    },//End of success function
    failure: function(record, operation) 
    {
        console.log("Inside failure functionnnnn");
    },//End of failure function
    callback: function(record, operation)
    {
        console.log("Inside callback functionnnnnn");   
    }//End of callback function
});// End of check save function

3)そしてデータはjson形式になります

{"records":{"userId":"","firstName":"ram","middleName":"","lastName":"","languageId":"","primaryEmail":"","birthDate":"","password":"sham","securityQuestionId":"","securityQuestionAnswer":"","isMale":"","creationTime":"","ipAddress":"","confirmationCode":"","userStatusId":"","id":null}}

4)ただし、firstNameとpasswordのみを送信したい。すべてのフィールドを送信したくない。データをサーバー側に送信するにはどうすればよいですか。

この形式のjsonが欲しい

{"records":{"firstName":"ram","password":"sham"}}

いくつか提案をお願いします。

4

2 に答える 2

2

ライターのgetRecordData関数を上書きする必要があります。このような。

 writer:
            {
                type:'json',
                root:'records',
                getRecordData: function (record) { return {"firstName" :record.data.firstName,"password": record.data.password}; },
            },
于 2013-02-25T13:01:19.523 に答える
1

nscrobの回答はコーディングが少ないため、推奨される場合がありますが、モデルにはこれに対する組み込みの構成persist: falseもあります。モデルフィールドがサーバー側に送信されないようにします。

私見では、モデル構成は、煎茶の例でも使用されているようには見えません(または、煎茶の例では使用されていないためかもしれません)。また、クライアントに処理させるのではなく、モデルでデータ型を定義すると、ごくわずかなリソースを節約できると思います。たとえば、次のようになります。

Ext.define('ab.model.sn.UserModel',{
    extend: 'Ext.data.Model',
    //idproperty:'userId',//fields property first position pk.

    // using field type definitions and explicit persistance
    fields: [
        {name: 'userId',                type: 'int',    persist: false},
        {name: 'firstName',             type: 'string'},
        {name: 'middleName',            type: 'string', persist: false},
        {name: 'lastName',              type: 'string', persist: false},
        {name: 'languageId',            type: 'int',    persist: false},
        {name: 'primaryEmail',          type: 'string', persist: false},
        {name: 'birthDate',             type: 'date',   dateFormat: 'c', persist: false},
        {name: 'password',              type: 'string'},
        {name: 'securityQuestionId',    type: 'int',    persist: false},
        {name: 'securityQuestionAnswer', type: 'string',persist: false},
        {name: 'isMale',                type: 'bool',   persist: false},
        {name: 'creationTime',          type: 'date',   dateFormat: 'c', persist: false},
        {name: 'ipAddress',             type: 'string', persist: false},
        {name: 'confirmationCode',      type: 'string', persist: false},
        {name: 'userStatusId',          type: 'int',    persist: false}
    ],
    proxy:
    {
        type:'ajax',
            //type:'localstorage',
            //id:'users',
        api:
        {
            read:'http://localhost/balaee/Balaee/index.php/SocialNetworking/user/AuthenticateLogin',
            create:'http://localhost/balaee/Balaee/index.php/SocialNetworking/user/AuthenticateLogin122',
            update:'http://localhost/balaee/Balaee/index.php/SocialNetworking/user/AuthenticateLogin123'
        },//end of api
        reader:
        {
            type:'json',
        },//end of reader
        writer:
        {
            type:'json',
            root:'records',
        },//End of writer

    }//end of proxy
});

私が言ったように、もう少しコーディングがありますが、私はこれを(オーバーライドの代わりに)このシナリオの組み込み処理としてそこに捨てると思いました。必要に応じてフィールドタイプの定義を削除することもできpersistます。プロパティを定義する必要はありません。

于 2013-02-25T18:03:22.177 に答える