我在主视图中声明了包含。那么如何在控制器中访问。在这里,我有 democontainer 和 demopanel 。所以如何访问它。
Ext.define('MyApp.view.Main', {
extend: 'Ext.Panel',
alias: 'widget.mainpage',
config: {
width: 710,
margin: '10px auto 0',
itemId: 'democontainer',
layout: {
type: 'hbox'
},
items: [
{
xtype:'container',
cls:'wholeMenuWrap',
margin: '65px 0 0 0',
width: 175,
items:[
....and
{
xtype: 'homepage',
cls:'homepage-wrap',
itemId: 'demopanel',
layout: {
type: 'fit'
}
},
{
xtype:'container',
layout: 'vbox',
margin: '65px 0 0 0',
width: 185,
items:[
{
xtype: 'titlebar',
cls:'roundedToolbar',
我想在这样的控制器上访问,但我无法访问它。
config: {
main:this,
profile: Ext.os.deviceType.toLowerCase(),
refs:{
myContainer: 'mainpage',
},
control: {
'mainpage': {
activate: 'onActivate',
itemtap: 'onItemTap',
},
'mainpage textfield[itemId=searchBox]' : {
//clear the input text box
clearicontap : 'onClearSearch',
//on every key stroke
keyup: 'onSearchKeyUp'
},
........
onSearchKeyUp: function(searchField) {
var container = this.up('#democontainer');
var panel = container.down('#demopanel');
panel.removeInnerAt(0);
var submitWordBySearch = { xtype: 'searchplusfav' };
panel.insert(0, submitWordBySearch);
我收到此错误:
Uncaught TypeError: Object [object global] has no method 'up'
任何人都可以帮帮我。
我添加了新代码:
refs:{
myContainer: 'mainpage',
demoContainer2: '#democontainer', //same as demoContainer1
demoContainer3:'#demopanel'
},
...-------------
onSearchKeyUp: function(searchField) {
var container = this.getDemoContainer2();
var panel = container.getDemoContainer3();
panel.removeInnerAt(0);
var submitWordBySearch = { xtype: 'searchplusfav' };
panel.insert(0, submitWordBySearch);
获取错误:
Uncaught TypeError: Object [object global] has no method 'demoContainer2'
工作代码:
onKeySubmitTap: function(dataview, index, target, record, e, options)
{
var container = dataview.up('#democontainer');
var panel = container.down('#demopanel');
panel.removeInnerAt(0);
var submitWordBySearch = { xtype: 'categorywordsdisplay' };
panel.insert(0, submitWordBySearch);
}
答案 0 :(得分:2)
我为自己的问题添加了这个,这是完全正确的工作:
var container = Ext.Viewport.up('#democontainer');
var panel = Ext.Viewport.down('#demopanel');
panel.removeInnerAt(0);
var submitWordBySearch = { xtype: 'submitnewdefinitionholder' };
panel.insert(0, submitWordBySearch);
答案 1 :(得分:0)
在控制器中使用this.up()
实际上不会做任何事情。要获得对democontainer的引用,首先应该意识到在类的itemId
中声明config
是没用的;这应该在声明一个类实例时完成。您基本上已经引用了#democontainer
,因为这两个与您当前的类配置相同:
refs: {
demoContainer1: 'mainpage',
demoContainer2: '#democontainer' //same as demoContainer1
}
因此,使用您已有的ref
,稍后在控制器中获取该引用,您需要使用的只是this.getMyContainer()
:
refs: {
myContainer: 'mainpage',
},
....
onSearchKeyUp: function(field) {
var container = this.getMyContainer();
....
}