Sencha touch 2 无法在sencha touch 2中获得存储
我将sencha touch中的商店定义如下: store.jsSencha touch 2 无法在sencha touch 2中获得存储,sencha-touch-2,undefined,store,Sencha Touch 2,Undefined,Store,我将sencha touch中的商店定义如下: store.js Ext.define('bluebutton.store.BlueButton.Testing', { extend: "Ext.data.Store", requires: [ 'bluebutton.model.BlueButton.Testing' ], config: { storeId: 'testingstore', mod
Ext.define('bluebutton.store.BlueButton.Testing', {
extend: "Ext.data.Store",
requires: [
'bluebutton.model.BlueButton.Testing'
],
config: {
storeId: 'testingstore',
model: 'bluebutton.model.BlueButton.Testing'
}
});
Model.js
Ext.define('bluebutton.model.BlueButton.Testing', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.proxy.LocalStorage'
],
config: {
fields: [
{ name: 'first', type: 'string' },
{ name: 'second', type: 'string' }
],
proxy: {
type: 'localstorage',
id: '_codeAnalyzerLocalStorage'
}
}
});
我需要打电话给getStore()
但是我得到了这个错误
getStore is undefined
请帮忙。谢谢您可以用
var test = Ext.getStore('testingstore');
Sencha Touch API:我用下面的代码进行了尝试,它可以正常工作 商店:
Ext.define('bluebutton.store.BlueButton.Testing', {
extend : "Ext.data.Store",
requires : [ 'bluebutton.model.BlueButton.Testing' ],
config : {
storeId : 'testingstore',
model : 'bluebutton.model.BlueButton.Testing'
}
});
型号:
Ext.define('bluebutton.model.BlueButton.Testing', {
extend : 'Ext.data.Model',
requires : ['Ext.data.proxy.LocalStorage'],
config : {
fields : [{
name : 'first',
type : 'string'
}, {
name : 'second',
type : 'string'
}],
proxy : {
type : 'localstorage',
id : '_codeAnalyzerLocalStorage'
}
}
});
视图:
app.js:
Ext.Loader.setConfig({
enabled : true,
});
Ext.application({
name : 'bluebutton',
views : [ 'BlueButton.Testing', ],
stores : [ 'BlueButton.Testing', ],
models : [ 'BlueButton.Testing', ],
launch : function() {
Ext.create('bluebutton.view.BlueButton.Testing');
}
});
按下按钮后,控制台会将存储记录给我
但我认为当你把按钮动作放在控制器中而不是视图中时,这将是一个更好的代码
button config:
{
xtype : 'button',
text : 'Test Local',
action : 'buttonTest'
}
控制器:
Ext.define('bluebutton.controller.BlueButton.Testing', {
extend : 'Ext.app.Controller',
config : {
control : {
'button[action="buttonTest"]' : {
tap : 'testButtonTap'
}
}
},
testButtonTap : function() {
var test = Ext.getStore('testingstore');
console.log(test);
}
});
你必须在app.js中添加你的商店 由于storeId引用的sencha bug(正如我所知,应用程序脚本的js加载顺序),您必须将存储放在stores数组中,所以如果您想使用 storeId,将您的店铺放入app.js 外部应用程序({
})) 嗨,我试试阿迪。你在app.js中提到你的商店时,是否也未定义?store:['BlueButton.Testing']您好,我已经输入了app.js,但仍然出现此错误。未捕获的TypeError:无法调用undefined的方法'getStore'
button config:
{
xtype : 'button',
text : 'Test Local',
action : 'buttonTest'
}
Ext.define('bluebutton.controller.BlueButton.Testing', {
extend : 'Ext.app.Controller',
config : {
control : {
'button[action="buttonTest"]' : {
tap : 'testButtonTap'
}
}
},
testButtonTap : function() {
var test = Ext.getStore('testingstore');
console.log(test);
}
});
name : 'bluebutton',
views : [ 'BlueButton.Testing', ],
stores : [ 'BlueButton.Testing', ], //this is the key
models : [ 'BlueButton.Testing', ],
launch : function() {
Ext.create('bluebutton.view.BlueButton.Testing');
}