You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ExtReact中最大化工具按钮实现报错:Uncaught TypeError: n.up is not a function

解决ExtReact最大化工具按钮的"Uncaught TypeError: n.up is not a function"错误

这个错误的核心原因是你工具按钮handler的参数签名不正确,导致你拿到的panelHdr并不是ExtReact的组件实例,自然没有up()这个Ext组件的内置方法。

问题分析

在ExtReact的组件工具(tool)配置中,handler的默认参数顺序是:(tool, event),而不是你写的(e, target, panelHdr)。你现在把事件对象当成了组件来调用up(),肯定会抛出类型错误。

修正方案

先调整handler的参数顺序,然后通过正确的组件实例来获取父级panel:

{
  type: 'maximize',
  handler: function(tool, event) {
    // 通过当前工具按钮向上查找panel组件
    var panel = tool.up('panel');
    if (!panel) return; // 确保找到panel再执行后续逻辑

    if (!panel.maximized) {
      panel.restoreSize = panel.getSize();
      panel.restorePos = panel.getPosition(true);
      panel.maximized = true;
      
      var parent = panel.ownerCt;
      var container = parent ? parent.getTargetEl() : panel.container;
      // 这里补充你的newBox逻辑...
    } else {
      // 记得补充还原的逻辑,避免状态不一致
      panel.setSize(panel.restoreSize);
      panel.setPosition(panel.restorePos);
      panel.maximized = false;
    }
  }
}

额外注意点

  • 调用up('panel')后最好做一下空值判断,避免找不到组件时后续代码报错。
  • 如果你的panel有特定的xtype或者itemId,也可以用up('your-custom-xtype')或者up('#your-item-id')来更精准地定位组件。
  • 记得维护maximized状态的切换,同时处理还原逻辑,保证组件状态的一致性。

内容的提问来源于stack exchange,提问作者Милош Рајковић

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:07:43