首页 \ 问答 \ Extjs 4.2中的自定义组件的多个实例(Multiple Instances of Custom Component in Extjs 4.2)

Extjs 4.2中的自定义组件的多个实例(Multiple Instances of Custom Component in Extjs 4.2)

我有一个名为“Teilgewerke”的网格面板。 我可以使用它作为面板的一个项目

{
    xtype:'panel',
    layout: {
        type: 'hbox',
        align: 'stretch'
    },              
    items:[
        {
            //xtype: 'teilgewerkegrid',
            id:'feinplanungPanelTeilgewerkeGrid',
            flex: 2
        },
        {
            xtype: 'panel',
            flex: 1
        }
    ]

}

但是现在当我尝试在另一个面板中使用它时,它会抛出以下错误:

Uncaught TypeError: Cannot read property 'isComponent' of undefined

我发现这个问题在指向完全相同的问题的Stackoverflow。 我尝试了上述链接中给出的解决方案,将项目放置为

initComponent: function() {
        this.items = [
            {
                xtype:'panel',
                flex: 5,
                border: false,
                padding: '0 20 0 20',
                items:[
                    {
                        xtype: 'text',
                        text: 'Teilgewerke für Aufbau an beteiligte Gruppen senden.',
                    }
                ]               
            },


            Ext.create('PfalzkomApp.view.TeilgewerkeGrid', {
                padding: '0 20 0 20',
                id:'aufbauTabTeilgewerkeGrid',
                flex: 90            
            }),

            {
                xtype: 'panel',
                border: false,
                padding: '0 20 0 20',
                flex: 5             
            }

        ]
    this.callParent();
}

但我仍有同样的问题。 有人可以指出我的错误吗?


I have a grid panel named "Teilgewerke". I am able to use it as an item of a panel like

{
    xtype:'panel',
    layout: {
        type: 'hbox',
        align: 'stretch'
    },              
    items:[
        {
            //xtype: 'teilgewerkegrid',
            id:'feinplanungPanelTeilgewerkeGrid',
            flex: 2
        },
        {
            xtype: 'panel',
            flex: 1
        }
    ]

}

But now when I try to use it inside another panel, it throws following error:

Uncaught TypeError: Cannot read property 'isComponent' of undefined

I found this question on Stackoverflow which is pointing to exact same problem. I tried the solution given in above link, by putting items as

initComponent: function() {
        this.items = [
            {
                xtype:'panel',
                flex: 5,
                border: false,
                padding: '0 20 0 20',
                items:[
                    {
                        xtype: 'text',
                        text: 'Teilgewerke für Aufbau an beteiligte Gruppen senden.',
                    }
                ]               
            },


            Ext.create('PfalzkomApp.view.TeilgewerkeGrid', {
                padding: '0 20 0 20',
                id:'aufbauTabTeilgewerkeGrid',
                flex: 90            
            }),

            {
                xtype: 'panel',
                border: false,
                padding: '0 20 0 20',
                flex: 5             
            }

        ]
    this.callParent();
}

But I still have same issue. Can someone point out my mistake?


原文:https://stackoverflow.com/questions/33823075
更新时间:2023-12-21 19:12

最满意答案

首先,我建议你采用面向对象的方法来分割每个组件的行为。

通过这种方式,您将拥有一个类App,您可以在其中初始化应用程序的主要组件:

class App(tk.Tk):

    def __init__(self,parent):
        Tk.__init__(self,parent)
        self.parent = parent
        self.initialize()

    def initialize(self):
        ...

        ...
        # Menubar
        self.menubar = MyMenuBar(self)

        # Filemenu
        self.filemenu = MyFileMenu(self, menubar)

        # Plot
        self.plot = MyPlot(self, menubar)

        # The rest for all the other components
        ...

    def get_import_filename(self):
        # Ask the child for the filename and return it
        return self.filemenu.get_filename()

然后定义每个对象:

class MyPlot(tk.Menu):
      def __init__(self, parent, menubar):
           tk.Menu.__init__(self, menubar, tearoff=0)
           self.parent = parent
           self.initialize()

      def initialize(self):
          self.add_command(label="Plot My CSV File", command= self.popupgraph)  

      def popupgraph(self):
          # Ask the parent for the filename
          filename = self.parent.get_import_filename()
          # Do whatever with the filename...like open a file

class MyFileMenu(tk.Menu):
      def __init__(self, parent, menubar):
           tk.Menu.__init__(self, menubar, tearoff=0)
           self.parent = parent
           self.initialize()
      def initialize(self):
          self.add_command(label="Import a CSV File", command = file_opener)
      def file_opener(self):
          # Your file opener function goes here
          ...
          # At the end, save the imported file:
          self.filename = filename
      def get_filename(self):
          return self.filename

最后,主要运行它:

def main():
    app = App(None)
    app.title('Auto login')
    app.mainloop()

if __name__ == "__main__":
    main()

First of all, I would suggest you take an Object Oriented approach to split each component behaviour.

This way, you would have a class App, where you would initialise the main components of the app:

class App(tk.Tk):

    def __init__(self,parent):
        Tk.__init__(self,parent)
        self.parent = parent
        self.initialize()

    def initialize(self):
        ...

        ...
        # Menubar
        self.menubar = MyMenuBar(self)

        # Filemenu
        self.filemenu = MyFileMenu(self, menubar)

        # Plot
        self.plot = MyPlot(self, menubar)

        # The rest for all the other components
        ...

    def get_import_filename(self):
        # Ask the child for the filename and return it
        return self.filemenu.get_filename()

And then define every of your objects:

class MyPlot(tk.Menu):
      def __init__(self, parent, menubar):
           tk.Menu.__init__(self, menubar, tearoff=0)
           self.parent = parent
           self.initialize()

      def initialize(self):
          self.add_command(label="Plot My CSV File", command= self.popupgraph)  

      def popupgraph(self):
          # Ask the parent for the filename
          filename = self.parent.get_import_filename()
          # Do whatever with the filename...like open a file

class MyFileMenu(tk.Menu):
      def __init__(self, parent, menubar):
           tk.Menu.__init__(self, menubar, tearoff=0)
           self.parent = parent
           self.initialize()
      def initialize(self):
          self.add_command(label="Import a CSV File", command = file_opener)
      def file_opener(self):
          # Your file opener function goes here
          ...
          # At the end, save the imported file:
          self.filename = filename
      def get_filename(self):
          return self.filename

Finally, have the main to run it:

def main():
    app = App(None)
    app.title('Auto login')
    app.mainloop()

if __name__ == "__main__":
    main()

相关问答

更多
  • 这是因为&menu_file('n')是调用子例程的语法( 更多细节 )。 相反,你必须这样做: $mw->bind('' => sub{menu_file('n')}); 或者像这样: $mw->bind('' => [\&menu_file, 'n']); That's because &menu_file('n') is syntax for invoking a subroutine (more details). Instead, you have ...
  • 您无法在Windows或OSX上更改菜单栏的颜色。 有可能在linux上的一些窗口管理器上,虽然我不确定。 原因是菜单栏是使用不由tkinter管理的本机小部件绘制的,因此您只能使用平台允许的内容。 You cannot change the color of the menubar on Windows or OSX. It might be possible on some window managers on linux, though I don't know for certain. The re ...
  • 在添加任何小部件之前先添加菜单栏 import wx import wx.grid as gridlib class ScrollbarFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY,"Grid with Popup Menu") self.layout_file = {'ID':[1,5,5],'NAME':[6,12],'STATE':[13 ...
  • 如果您在谈论根窗口的menu属性时获得的本地菜单栏,则不能。 您可以使用框架和一个或多个menubutton创建自己的菜单栏,其行为有点像菜单栏,并将其置于底部。 You can't, if you're talking about the native menubar you get when you set the menu attribute of the root window. You can create your own menubar that behaves a little bit li ...
  • 您可以使用方法MenuItem.addActionListener(ActionListener)将实现ActionListener接口的类的对象添加到菜单项,如下所示: menuItem.addActionListener(actionListener); You can add an object of a class that implements the ActionListener interface to the menu item by using the method MenuItem.a ...
  • 问题是菜单的高度高于应用程序的高度。 所以它正在显示但它已经离开了屏幕。 我猜测逻辑是,如果弹出菜单的任何部分不在屏幕上,则菜单栏必须沿着应用程序的底部放置,因此弹出菜单应显示在菜单栏上方而不是下方。 解决方法是让屏幕更高(我看到Firebug,因此它不是典型的高度)。 我可以检查弹出窗口的高度,并将其与应用程序的高度进行比较,并手动将弹出的垂直位置设置为正确的位置。 我没有尝试解决它超出这一点,因为用户可能不会在这么短的高度使用该应用程序。 The problem was the height of th ...
  • 此处描述了类似的问题: 如何指定打开URL的按钮? 一种可能的方案: public class MyMenuBar extends MenuBar { ResourceReference rr; public MyMenuBar() { Resource pdf = new FileResource(new File("C:/temp/temp.pdf")); setResource("help", pdf); rr = ResourceR ...
  • 首先,我建议你采用面向对象的方法来分割每个组件的行为。 通过这种方式,您将拥有一个类App,您可以在其中初始化应用程序的主要组件: class App(tk.Tk): def __init__(self,parent): Tk.__init__(self,parent) self.parent = parent self.initialize() def initialize(self): ... ... ...
  • 您可以将非本机QMenuBar放置在布局中,就像任何其他窗口小部件一样。 下面是一个示例应用程序。 #include #include #include int main(int argc, char **argv) { QApplication app(argc, argv); QWidget window; QVBoxLayout layout(&window); QMenuBar menu ...
  • NSApplication *app = [NSApplication sharedApplication]; [app activateIgnoringOtherApps:YES]; [NSApp orderFrontStandardAboutPanel:sender]; 请尝试上面的代码。 NSApplication *app = [NSApplication sharedApplication]; [app activateIgnoringOtherApps:YES]; [NSApp orderFr ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)