Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class Ext.define()顺序_Class_Extjs - Fatal编程技术网

Class Ext.define()顺序

Class Ext.define()顺序,class,extjs,Class,Extjs,我正在使用Extjs5和Sencha Cmd,并且正在开发一个l10n引擎(通过gettext)来实现本地化 假设我想为我的项目中的每个类提供一个翻译函数,名为。 在每个控制器、视图、模型和任何类中,我都希望能够编写如下内容: Ext.define('FooClass', { someStrings: [ _('One string to translate'), _('A second string to translate'), _('Yet another st

我正在使用Extjs5和Sencha Cmd,并且正在开发一个l10n引擎(通过gettext)来实现本地化

假设我想为我的项目中的每个类提供一个翻译函数,名为

在每个控制器、视图、模型和任何类中,我都希望能够编写如下内容:

Ext.define('FooClass', {
  someStrings: [
    _('One string to translate'),
    _('A second string to translate'),
    _('Yet another string to translate')
  ]
});
第一个问题:\必须在执行项目的所有Ext.define()之前存在。如何做到这一点

第二个问题:\正在查找由.po文件(gettext)生成的一些JavaScript文件的“目录”。因此,在我的应用程序的所有Ext.define()执行之前,这些目录必须已加载。
_()是一个同步函数,它必须立即返回已翻译的字符串。

编辑有关已编辑问题的内容

至少有两种方法可以加载外部库:

加载指定的脚本URL并调用提供的回调。如果 在Ext.isReady之前调用此方法,脚本的加载将延迟 过渡到就绪。这可用于加载任意脚本 可能包含更多的Ext.require调用

参数

options : Object/String/String[] //The options object or simply the URL(s) to load.
// options params:
url : String //The URL from which to load the script.
onLoad : Function (optional) //The callback to call on successful load.
onError : Function (optional) //The callback to call on failure to load.
scope : Object (optional) //The scope (this) for the supplied callbacks.
function _() {
    // do the translation
}
如果仍然遇到问题,可以强制加载程序执行同步加载:

syncLoadScripts: function(options) {
    var Loader = Ext.Loader,
        syncwas = Loader.syncModeEnabled;
    Loader.syncModeEnabled = true;
    Loader.loadScripts(options);
    Loader.syncModeEnabled = syncwas;
}
将此文件放在ExtJS库的正后方和生成的
app.js
之前的文件中


旧答案

当需要的时候,你需要一个类,它可以解决你的问题。如果您不需要sencha命令/ExtJS类,则系统无法知道您需要特定的类

Ext.define('Class1', {
  requires: ['Class2'], 
  items: [
    {
      xtype: 'combo',
      fieldLabel: Class2.method('This is a field label')
    }
  ]
});
进一步阅读请参阅:

在实例化之前必须加载的类的列表 班级。例如:

Ext.define('Mother', {
    requires: ['Child'],
    giveBirth: function() {
        // we can be sure that child class is available.
        return new Child();
    }
});
Ext.define('Mother', {
    uses: ['Child'],
    giveBirth: function() {
        // This code might, or might not work:
        // return new Child();

        // Instead use Ext.create() to load the class at the spot if not loaded already:
        return Ext.create('Child');
    }
});

要与此类一起加载的可选类的列表。这些 在创建此类之前不必加载,但是 保证在调用Ext.onReady侦听器之前可用。 例如:

Ext.define('Mother', {
    requires: ['Child'],
    giveBirth: function() {
        // we can be sure that child class is available.
        return new Child();
    }
});
Ext.define('Mother', {
    uses: ['Child'],
    giveBirth: function() {
        // This code might, or might not work:
        // return new Child();

        // Instead use Ext.create() to load the class at the spot if not loaded already:
        return Ext.create('Child');
    }
});

在ExtJs项目范围之外定义translate函数,并在index.html中包含Ext应用程序之前将其包含在内。 脚本按正确的顺序加载,
\uuz()
函数可以在整个项目中使用

i18n.js

options : Object/String/String[] //The options object or simply the URL(s) to load.
// options params:
url : String //The URL from which to load the script.
onLoad : Function (optional) //The callback to call on successful load.
onError : Function (optional) //The callback to call on failure to load.
scope : Object (optional) //The scope (this) for the supplied callbacks.
function _() {
    // do the translation
}
index.html

<html>
    <head>
        <script src="i18n.js"></script>
        <script id="microloader" type="text/javascript" src="bootstrap.js"></script>
    </head>
    <body>

    </body>
</html>


谢谢你的回答,但我意识到我的问题的格式不正确,我的问题比这更复杂,我尝试重新表述。谢谢,在我的项目的app.json的“js”部分添加了一些文件就完成了。很遗憾,我不能为i18n.js工具使用Extjs工具,但这不是一个真正的问题。