Sencha touch 2 Sencha localStorage.getItem()在模型中返回null
在我的模型中,我有以下代码:Sencha touch 2 Sencha localStorage.getItem()在模型中返回null,sencha-touch-2,Sencha Touch 2,在我的模型中,我有以下代码: Ext.define('Proximity.model.CandidateblocklistModel', { extend: 'Ext.data.Model', requires: ['Ext.data.proxy.LocalStorage'], config: { store:'Proximity.store.CandidateblockStore', fields: [ { nam
Ext.define('Proximity.model.CandidateblocklistModel', {
extend: 'Ext.data.Model',
requires: ['Ext.data.proxy.LocalStorage'],
config: {
store:'Proximity.store.CandidateblockStore',
fields: [
{ name: 'id', type: 'id' },
{ name: 'name', type: 'string' },
{ name: 'img', type: 'string' },
{ name: 'designation', type: 'string' },
{ name: 'summary', type: 'string' },
{ name: 'experience', type: 'string' },
{ name: 'industry', type: 'string' },
{ name: 'functionnml', type: 'string' },
{ name: 'role', type: 'string' }
],
proxy : {
type : 'ajax',
url : Proximity.util.Config.getBaseUrl() + '/index.php/candidate/getcandidateblock',
withCredentials: false,
useDefaultXhrHeader: false,
extraParams: {
"id": localStorage.getItem('id')
},
reader : {
filters: [
Ext.create('Ext.util.Filter', {
property: 'name'
})
]
}
}
}
});
在调用此模型之前,已设置本地存储中的id。我可以通过Chrome中的inspect元素在localStorage中查看id,并且在其他部分中得到了它的值。但我只是在我的模型中无法得到它,当我试图在代理中使用它时。我希望根据本地存储的值从web服务获取数据
我的代理中的代码:
extraParams: {
"id": localStorage.getItem('id')
},
我想在这里从localStorage获取id
请帮帮我。啊,我发现了一个很棒的把戏。在您的模型中安装设置
extraParams
,然后在同一模型的存储中进行设置。
我的新代码如下。
Ext.define('approxity.model.recruiterTestListModel'{
扩展:“Ext.data.Model”,
配置:{
store:'Proximition.store.RecruiterbestStore',
字段:[
{name:'id',type:'int'},
{name:'name',type:'string'},
{name:'img',type:'string'},
{name:'company',type:'string'},
{name:'summary',键入:'string'},
{name:'address',type:'string'},
{name:'industry',type:'string'},
{name:'functionnml',键入:'string'},
{name:'role',type:'string'}
],
代理:{
键入:“ajax”,
url:approxity.util.Config.getBaseUrl()+'/index.php/recruiter/getrecruiterbest/',
使用凭据:false,
useDefaultXhrHeader:false,
读者:{
过滤器:[
Ext.create('Ext.util.Filter'{
属性:“ind_id”,
属性:'fun_id',
属性:“角色\u id”
})
]
}
}
}
});代码>
看,我已经删除了代码
外部参数:{
“id”:localStorage.getItem('id')
},
从模型。在我的商店里,我添加了
侦听器:{
加载前:函数(存储){
此.getProxy().setExtraParams({
id:localStorage.getItem('id')
});
返回true;
},
所以我的新商店代码如下
Ext.define('approxity.store.RecruiterbestStore'{
扩展:“Ext.data.Store”,
别名:“store.RecruiterTestStore”,
配置:{
model:'approxity.model.recruiterTestListModel',
自动加载:对,
remoteFilter:true,
storeId:“招聘网站商店”
},
听众:{
加载前:函数(存储){
此.getProxy().setExtraParams({
id:localStorage.getItem('id')
});
返回true;
}
}
});
它解决了我的问题
但现在我又遇到了另一个问题。在运行sencha app build native
(使用cordova bild)之后,我又遇到了同样的问题,extraParam
没有添加到代理请求中
请帮我解决这个问题。我认为下面的代码可以工作
proxy : {
type : 'ajax',
url : Proximity.util.Config.getBaseUrl() + '/index.php/candidate/getcandidatebest',
withCredentials: false,
useDefaultXhrHeader: false,
extraParams: {
id: localStorage.getItem('id')
},
reader : {
filters: [
Ext.create('Ext.util.Filter', {
property: 'ind_id',
property: 'fun_id',
property: 'role_id',
property: 'id'
})
]
}
}
然后使用store的筛选功能传递localstorage值。为此,请授予筛选权限remoteFilter:true,
此操作。我遇到另一个问题。运行sencha app build native后(使用cordova bild),我又遇到了同样的问题,extraParam
未添加到代理请求中。请尝试解决此问题。这不会提供问题的答案。若要提出新问题,请使用“提问”按钮。如果有助于提供上下文,您可以链接到此问题。是的,因为我是stackoverflow新手,我不知道如何链接当您键入问题时,有一个链接图标(带箭头的小地球仪)。你可以用这个链接到这个问题。好的@EdCottrell非常感谢你……我会记住这一点。非常感谢。