我在sencha touch中定义store如下:
store.js
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()
Ext.define('bluebutton.view.BlueButton.testing', {
extend: 'Ext.form.Panel',
xtype: 'testing',
requires: [
'bluebutton.view.BlueButton.TransactionList',
'bluebutton.view.BlueButton.MemberPopUp',
'bluebutton.view.BlueButton.MemberDetail',
'bluebutton.store.BlueButton.MemberList',
'bluebutton.model.BlueButton.Testing',
'bluebutton.store.BlueButton.Testing'
],
config: {
id:'register',
items :[
{
xtype: 'textfield',
name: 'name',
label: 'Name'
},
{
xtype: 'emailfield',
name: 'email',
label: 'Email'
},
{
xtype: 'button',
text: 'Test Local',
handler: function(button) {
var test = Ext.getCmp('testingstore').getStore();
alert(test);
}
},
],
}
});但是我得到了这个错误
getStore is undefined请帮帮忙。谢谢
发布于 2015-02-15 10:10:11
你必须在app.js中添加你的商店
你必须将你的商店放在商店数组中,因为storeId引用的sencha错误(据我所知,应用程序脚本的js加载顺序),所以如果你想使用storeId,把你的商店放在app.js中。
Ext.application({
name : 'bluebutton',
views : [ 'BlueButton.Testing', ],
stores : [ 'BlueButton.Testing', ], //this is the key
models : [ 'BlueButton.Testing', ],
launch : function() {
Ext.create('bluebutton.view.BlueButton.Testing');
}});
发布于 2013-01-29 16:13:07
我试着用下面的代码,它工作起来没有任何问题!
商店:
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'
}
}
});查看:
Ext.define('bluebutton.view.BlueButton.Testing', {
extend : 'Ext.form.Panel',
xtype : 'testing',
config : {
fullscreen : true,
id : 'register',
items : [{
xtype : 'textfield',
name : 'name',
label : 'Name'
}, {
xtype : 'emailfield',
name : 'email',
label : 'Email'
}, {
xtype : 'button',
text : 'Test Local',
handler : function(button) {
var test = Ext.getStore('testingstore');
console.log(test);
}
}]
}
});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);
}
});发布于 2013-01-25 18:00:35
你可以用以下命令获得商店:
var test = Ext.getStore('testingstore');Sencha Touch接口:http://docs.sencha.com/touch/2-1/#!/api/Ext-method-getStore
https://stackoverflow.com/questions/14519064
复制相似问题