gpt4 book ai didi

extjs - 如何在 extjs4 中调用动态设置的代理类型?

转载 作者:行者123 更新时间:2023-12-01 01:11:26 25 4
gpt4 key购买 nike

我在 extjs4 MVC 中工作。我将停留在我将动态代理类型设置为“localstorage”的地方,我将替换在模型类中声明的“ajax”代理类型。
当我想在客户端存储数据时,我将我的模型代理类型从 ajax 更改为 locastorage。但是当我在特定模型对象上调用 save() 方法时,数据将不会保存在客户端。给我一些建议

1)这是我的模型数据类

Ext.define('Am.model.sn.UserModel',{
extend: 'Ext.data.Model',
fields: ['userId','firstName','middleName','lastName','languageId','primaryEmail','birthDate','password','securityQuestionId','securityQuestionAnswer','isMale','creationTime','ipAddress','confirmationCode','userStatusId',],
proxy:
{
type:'ajax',
api:
{
read:'index.php/SocialNetworking/user/AuthenticateLogin',
create:'index.php/SocialNetworking/user/AuthenticateLogin',
},//end of api
reader:
{
type:'json',
},//end of reader
writer:
{
type:'json',
root:'records',
},//End of writer
}//end of proxy
});

2)这是我的一些 Controller 文件代码
Ext.define('Am.controller.sn.UserController',
{

extend:'Ext.app.Controller',

stores:['sn.UserStore','sn.SecurityquestionStore'],
models:['sn.UserModel','sn.SecurityquestionModel'],
views:['sn.user.Login','sn.user.Registration','sn.user.ForgetMyKey','sn.user.SecurityQuestion','sn.user.KpLogin'],
-----
----
init:function()
{
--------
}
remeberMe:function()
{
console.log("check box selected");
var email=this.getUserName().getValue();
var password=this.getPassword().getValue();
var objCheckBox=Ext.getCmp('checkbox');
if(objCheckBox.getValue()==true)
{
window.localStorage.clear();
//code for stoaring data at local storage
var modelObject = Ext.ModelManager.create(
{
primaryEmail:email,
password: password,
}, 'Balaee.model.sn.UserModel');
proxy=modelObject.getProxy();
//proxy=modelObject.getProxy();
proxy.type='localstorage';
//proxy.set(type,'localstorage');
proxy.id='rememberMe';
//proxy.set(id,'rememberMe');
//modelObject.setProxy(proxy);
//console.log("models proxyyyyyyyyyy="+modelObject.getProxy().type+""+modelObject.getProxy().id);

modelObject.setProxy(proxy);
//
I am also trying this but not work
//Ext.apply(proxy,{type:'localstorage',id:'remember' });

modelObject.save();
// code to hide login window
//var obj=Ext.ComponentQuery.query('#loginId');
//console.log("Object name = "+obj[0].id);
//obj[0].hide();
}//end of if statement
else
{
console.log("check box is not selected");
}//end of else statement
},//End of rememberMe function

});

请给我一些建议.....

最佳答案

我创建了一个示例代码,以便更好地理解切换代理。

//Defining model
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [{name: 'name', type: 'string'}]
});
//creation of ajax proxy
var ajaxProxy = new Ext.data.proxy.Ajax({
id: 'ajaxp',
reader: 'json'
});
//creation of local storage proxy
var lsProxy = new Ext.data.proxy.LocalStorage({
id: 'localp',
reader: 'json'
});
//Create instance of model
var user = Ext.create('User', {
name : 'Pravin Mane',
proxy: ajaxProxy //sets the ajax proxy
});

//Somewhere in your code
user.setProxy(lsProxy); //sets the localstorage proxy

关于extjs - 如何在 extjs4 中调用动态设置的代理类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15219945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com