ExtJS 4 MVC multiple instances of views and sub/child controller difficulties

前端 未结 7 1040
情书的邮戳
情书的邮戳 2021-02-07 13:01

I have encountered a problem with the MVC pattern in ExtJS 4. At least, I think I have. Having approached multiple people with this question, and having posted numerous times in

7条回答
  •  死守一世寂寞
    2021-02-07 14:01

    This can be done, reasonably easily. You need to follow a few rules:

    1. load your controllers at app startup. Don't unload them. Don't worry about the memory or time, it's pretty small even for hundreds of controllers, as long as you minimize and concatenate your js.

    2. Never use the refs or views properties of a controller. You are going to use one instance of a controller, but multiple instances of views, so you never want a reference to a view.

    3. only use event listeners in controllers. You are only going to listen to events on your views. You can always get a (temporary) reference to a view in the event handler via the "cmp" parameter in the handler.

    4. To "launch" a view, create it and add it to another view. To destroy it, destroy it. You don't use a controller to launch a view. You can use the afterrender and beforedestroy events in the controller to add logic.

提交回复
热议问题