如何将 extjs4 文件分离到相关包中

发布于 2025-01-03 02:58:15 字数 290 浏览 2 评论 0原文

有一个带有 extjs4 前端的 symfony 2 项目。我从一个 extjs 包开始,它现在包含整个 extjs 应用程序。问题是随着项目的增长,管理将变得困难。

我认为,最好的解决方案是将所有 extjs 文件重新定位到相关的包
(例如:将所有表单、面板、网格等添加到 UserBundle 中)并使用中央 Extjs 包来加载它们。

以这种方式组织项目的最佳实践是什么?
以及如何包含另一个包中的 js 文件?
或者我应该为每个包创建 extjs 应用程序(我不确定这是否明智)?

There is a symfony 2 project with extjs4 frontend. I started with an extjs bundle which contains now the entire extjs app. The problem is it will be difficult to manage as the project grows.

I think , the best solution would be to relocate all extjs file to the related bundle
(e.g.: to the UserBundle all forms, panel, grid etc. ) and use a central Extjs bundle to load them.

What is the best practice to organize a project in this manner?
And how to include the js files from another bundle?
Or should I create extjs app to every bundle (I'm not sure it would be wise) ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2025-01-10 02:58:15

我不确定这是否是最佳实践,但我知道这适用于 ExtJs 4.0.7。

例如,我有以下文件夹结构:

proj
  index.htm
  proj
    app.js
    app
      view
        SimpleIFrame.js

因此,在 app.js 中,我有以下代码:

Ext.Loader.setConfig(
{
    enabled: true
});
Ext.Loader.setPath('proj.view', './proj/app/view');
Ext.Loader.require([
    'proj.view.SimpleIFrame'
])

在 SimpleIFrame 中,我有以下代码:

Ext.define('proj.view.SimpleIFrame', {
  extend: 'Ext.Panel',
  alias: 'widget.simpleiframe',
  ...
  });

那么稍后在 app.js 中,我可以执行以下操作:

var panel = Ext.create('adminClaiming.view.SimpleIFrame', {
  title: 'Hello',
  ...
});

这允许我分离整个应用程序.js 分成单独的文件。直到我弄清楚这一点之前,我一直收到可怕的消息:

Uncaught TypeError: object is not a function

这只是意味着我忘记调用 Ext.Loader.setPath。

现在不要在接下来的部分引用我,但似乎如果您删除 Ext.require 然后 SimpleIFrame.js 被加载到全局命名空间中,这不是你真正想要的,但它仍然被加载,并且它确实工作,这是更重要的。

希望有帮助。请注意,我很可能都是错的;),并且就我而言,我很幸运;我能做什么,我还是个n00b。

I'm not sure this is best practice, but I know this works on ExtJs 4.0.7.

So for example I have the following folder structure:

proj
  index.htm
  proj
    app.js
    app
      view
        SimpleIFrame.js

So in app.js I have the following code:

Ext.Loader.setConfig(
{
    enabled: true
});
Ext.Loader.setPath('proj.view', './proj/app/view');
Ext.Loader.require([
    'proj.view.SimpleIFrame'
])

In SimpleIFrame I have the following code:

Ext.define('proj.view.SimpleIFrame', {
  extend: 'Ext.Panel',
  alias: 'widget.simpleiframe',
  ...
  });

So then later in app.js I can do the following:

var panel = Ext.create('adminClaiming.view.SimpleIFrame', {
  title: 'Hello',
  ...
});

That allows me to separate the whole app.js into separate files. Up until I figured this out I kept getting the dreaded:

Uncaught TypeError: object is not a function

Which just meant that I'd forgotten to call Ext.Loader.setPath.

Now don't quote me on this next bit, but it seems that if you remove the Ext.require then SimpleIFrame.js is loaded in the global namespace, which is not really what you want, but it's still loaded, and it does work, which is more important.

Hope that helps. And mind you I will be most likely all be wrong ;), and had just gotten lucky in my case; what can I do, I'm still a n00b.

樱娆 2025-01-10 02:58:15

您可以将 JS 文件与每个文件的 Resources/public/js 中的文件分开打包。

然后,在您的主 html 模板上,您可以使用 assetic 包含所有 JS 文件。

You could make separates bundles with your JS files inside Resources/public/js of each of them.

Then, on your main html template you could include all your JS Files using assetic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文