Sencha Touch 2自定义休息代理网址

问题描述:

我有一个休息API和用户认证,其余的网址是: https://api.abc.com/user/ {用户名}/{密码}。所以我需要为其他代理设置两个参数。谁能帮帮我吗?Sencha Touch 2自定义休息代理网址

这里是我的用户模型:

Ext.define('NCAPP.model.User', { 
extend:'Ext.data.Model', 

config:{ 
    fields:[ 
     { name:'id', type: 'int'},   
     { name: 'username', type: 'string'}, 
     { name: 'netshop_id', type:'int'}, 
     { name: 'firstname', type: 'string'}, 
     { name: 'lastname', type: 'string'}, 
     { name: 'address', type: 'string'}, 
     { name:'password', type:'string'}, 

    ], 

    proxy: { 
     type:'rest', 
     url:https://api.abc.com/user/', 
     noCache: false,   
     reader: { 
      type:'json', 
      rootProperty:'user' 
     }    

    } 

} 

});

这里是我的loginbuttion Tap功能的LoginController:

onLoginButtonTap:function(){ 

    var values=this.getLoginForm().getValues(); 

    Ext.ModelMgr.getModel('NCAPP.model.User').load(values.username,{ 
     success: function(user){ 
      if(user==null) 
       { 
        Ext.Msg.alert('NCAPP',"Invalid username or password!"); 
       } 
       else 
       { 
        Ext.Msg.alert('NCAPP','Welcome! '+user.get('username')); 
        //do after login implementation 
       } 

     }, 
     failure: function(user){ 
      console.log("Uff, Something went worng!"); 
     } 
    });  
}, 

在以下行,我想通过用户名和密码: Ext.ModelMgr.getModel( 'NCAPP.model.User') .load(values.username,values.password,{.....

谁能帮助我实现这个目标?

您可以使用方法“setProxy”动态代理添加到您的模型/商店。

var values = this.getLoginForm().getValues(); 
YOURMODEL.setProxy({ 
    proxy: { 
     type: 'rest', 
     url: 'https://api.abc.com/user/'+ values.username +'/'+ values.password, 
     noCache: false,   
     reader: { 
      type: 'json', 
      rootProperty: 'user' 
     }    

    } 
});