use*_*405 2 store undefined sencha-touch-2
我在sencha touch中定义了商店如下:
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'
}
});
Run Code Online (Sandbox Code Playgroud)
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'
}
}
});
Run Code Online (Sandbox Code Playgroud)
我需要调用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);
}
},
],
}
});
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个错误
getStore is undefined
Run Code Online (Sandbox Code Playgroud)
请帮忙.谢谢
小智 5
我尝试使用以下代码,它没有问题!
商店:
Ext.define('bluebutton.store.BlueButton.Testing', {
extend : "Ext.data.Store",
requires : [ 'bluebutton.model.BlueButton.Testing' ],
config : {
storeId : 'testingstore',
model : 'bluebutton.model.BlueButton.Testing'
}
});
Run Code Online (Sandbox Code Playgroud)
模型:
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'
}
}
});
Run Code Online (Sandbox Code Playgroud)
视图:
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);
}
}]
}
});
Run Code Online (Sandbox Code Playgroud)
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');
}
});
Run Code Online (Sandbox Code Playgroud)
按下按钮后,控制台会记录我的商店.
但是当我把按钮动作放在控制器中而不是视图时,我认为这将是一个更好的代码!
button config:
{
xtype : 'button',
text : 'Test Local',
action : 'buttonTest'
}
Run Code Online (Sandbox Code Playgroud)
控制器:
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);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7680 次 |
| 最近记录: |