gpt4 book ai didi

sencha-touch-2 - 无法在 sencha touch 2 中获取存储

转载 作者:行者123 更新时间:2023-12-02 00:37:06 24 4
gpt4 key购买 nike

我在 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'
}
});

模型.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

请帮忙。谢谢

最佳答案

我用下面的代码尝试了它,它工作没有问题!

商店:

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');
}

});

按下按钮后控制台会记录我的商店。

但我认为当您将按钮操作放在 Controller 而不是 View 中时,这将是一个更好的代码!

button config:
{
xtype : 'button',
text : 'Test Local',
action : 'buttonTest'

}

Controller :

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);
}
});

关于sencha-touch-2 - 无法在 sencha touch 2 中获取存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14519064/

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