2013-02-25 29 views
1

我正在extjs4 MVC結構工作,我一直在extjs4 所有的領域提交到服務器端的問題,但我只想發送模型類的一些文件到服務器端。我怎樣才能得到這個輸出?如何在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)但我想只發送名字和密碼。我不想發送所有的字段。我怎樣才能將數據發送到服務器端。

我想以JSON格式

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

,請給我一些建議....

回答

2

你只需要覆蓋作家的getRecordData功能。喜歡這個。

writer: 
      { 
       type:'json', 
       root:'records', 
       getRecordData: function (record) { return {"firstName" :record.data.firstName,"password": record.data.password}; }, 
      }, 
+0

非常感謝。它解決了。 – 2013-02-25 13:54:28

+1

+1簡明 – Geronimo 2013-02-25 18:10:54

1

nscrob的回答少編碼,因此它可能是首選,但也有這個模型上的built-in configpersist: false。它使模型字段不被髮送到服務器端。

恕我直言模型configs似乎並沒有得到使用,他們甚至應該在sencha例子中(或者因爲它們沒有用在sencha例子中)。我想這也節約了資源的極小量,如果你在模型中定義的數據類型,而不是讓客戶做出來,例如:

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屬性。

+0

感謝您給我提供更多信息.. – 2013-02-26 07:56:49

相關問題