我正在尝试使用导航视图并对其执行推送和弹出操作,但无法找到确切定义对象视图的位置,该视图将用于view.push和view.pop。 因为我得到这个错误,视图没有定义! 如果尝试将Third_Navigate定义为var视图,如
var view = Ext.define('MyFirstApp.view.Third_Naviagte', { .. });
然后我得到错误view.push没有定义。帮助
Ext.define('MyFirstApp.view.Third_Naviagte', {
extend: 'Ext.navigation.View',
xtype: 'navigationview',
//itemId:'navView',
//we only give it one item by default, which will be the only item in the 'stack' when it loads
config:{
items: [
{
//items can have titles
title: 'Navigation View',
padding: 10,
//inside this first item we are going to add a button
items: [
{
xtype: 'button',
text: 'Push another view!',
handler: function() {
//when someone taps this button, it will push another view into stack
view.push({
//this one also has a title
title: 'Second View',
padding: 10,
//once again, this view has one button
items: [
{
xtype: 'button',
text: 'Pop this view!',
handler: function() {
//and when you press this button, it will pop the current view (this) out of the stack
view.pop();
}
}
]
});
}
}
]
}
]}
});
答案 0 :(得分:1)
var view = Ext.define(...);
的示例不起作用的原因是因为 Ext.define 与 Ext.create 不同,并不返回Object实例。它应该是var view = Ext.create(...);
。
替代方法是使用用于选择祖先的up
方法。
在你的处理程序函数中使用this
来获取按钮实例,然后你可以从那里选择导航视图:
handler: function() {
var view = this.up('navigationview');
view.push({
title: 'Second View',
padding: 10,
items: [
{
xtype: 'button',
text: 'Pop this view!',
handler: function() {
view.pop();
}
}
]
});
}