一个非常简单的问题.当前,当我需要在整个应用程序中访问对象的方法时该怎么做,我在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.
更多推荐
如何在没有循环引用的情况下在控制器之间共享对象/方法?
发布评论