如何在没有循环引用的情况下在控制器之间共享对象/方法?

编程入门 行业动态 更新时间:2024-10-24 17:32:47
本文介绍了如何在没有循环引用的情况下在控制器之间共享对象/方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一个非常简单的问题.当前,当我需要在整个应用程序中访问对象的方法时该怎么做,我在app.js

Pretty straightforward question. Currently, what I do when I need to access objects' methods throughout most of the application, I do this in app.js

Ext.define('Utils', { statics: { myMethod: function() { return 'myResult'; } } });

这可行,但是当我构建应用程序时,会收到关于循环引用的警告(当然,app.js需要所有其他控制器类,但随后这些类会引用回app.js).

This works, but when I build the application, I get a warning about a circular reference (app.js of course needs all the other controller classes, but then said classes refer back to app.js).

我考虑过使用一个包含.js文件的程序包,该文件包含所有对象/方法,但是有时,在这些方法中,我需要访问Ext命名空间,以使其无法正常工作.

I thought of using a package including a .js file that has all the objects/methods, but sometimes, within these methods I'll need access to the Ext namespace so that won't work.

还有更好的方法吗?

谢谢!

推荐答案

您不应在app.js内定义类Utils.每个Ext.define语句应位于其自己的文件中.另外,类名还应以您的应用程序名称为前缀.

You should not define the class Utils inside app.js. Each Ext.define statement should be in it's own file. Also the classname should be prefixed with your app name.

Ext.define('MyApp.Utils', { statics: { myMethod: function() { return 'myResult'; } } });

因此,应该在文件app/Utils.js中找到

.将源代码编译为已编译的app.js时,Sencha Cmd将注意最终文件中的正确顺序. requires和uses指令为您提供了足够的灵活性来定义类之间的任何依赖关系.

should therefore be found in the file app/Utils.js. When compiling your sources into a compiled app.js, Sencha Cmd will take care of the proper ordering in the final file. The requires and uses directives give you enough flexibility to define any dependences between your classes.

阅读有关MVC的所有文档,以获得清晰的了解.

Read all the docs about MVC to get a clear understanding.

更多推荐

如何在没有循环引用的情况下在控制器之间共享对象/方法?

本文发布于:2023-11-27 19:43:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639353.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   情况下   对象   方法   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!