将初始参数传递给 ExtJS 4 应用程序

发布于 2025-01-06 10:39:54 字数 303 浏览 3 评论 0原文

我对 ExtJS 和 javascript 框架绝对是全新的,这是一个非常简单的问题,但我似乎找不到一个例子。

我试图找出如何简单地将初始参数从托管 html 页面传递到 ExtJS 4 应用程序 - ExtJS 4 相当于应用程序托管 html 页面中这条非常简陋的行:

var myapp = new MyApp({param1:'value1', param2:'value2'});

我看到的所有内容:在线示例并不当应用程序启动时,最初不会将参数传递给应用程序。这是不是正确的想法或什么......?

I am absolutely brand new to ExtJS and javascript frameworks, and this is a dead simple question but I just can't seem to find an example.

I am trying to find out how I should simply pass initial arguments from the hosting html page to an ExtJS 4 application - what is the ExtJS 4 equivalent of this very humble line in the app's hosting html page:

var myapp = new MyApp({param1:'value1', param2:'value2'});

Everything I see re: examples online doesn't pass arguments initially to the application when it starts up. Is that just not the right idea or something..?

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

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

发布评论

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

评论(2

柳若烟 2025-01-13 10:39:54

我通常在页面上创建全局变量,然后在js中使用它们。
就像:

//mypage.html

 <script type="text/javascript">
        var loadScansUrl = "<%=Url.Action<ReportScannerRunController>(controller => controller.LoadScans())%>";
        var loadInstancesUrl = "<%=Url.Action<ReportScannerRunController>(controller => controller.LoadInstances(-1))%>";
 </script>

然后我直接在需要的地方使用它们。

//myfile.js

Ext.Ajax.request({
            url: loadInstancesUrl, // here is the usage!!!
            headers: {
                'Content-Type': 'application/json'
            },
            params: this.scanId,
            scope: this,
            success: function (response) {
                var result = Ext.decode(response.responseText);
                var comboData = [];
                Ext.each(result.Instances, function (instance) {
                    comboData.push({ Value: instance });
                });
                instances.store.loadData(comboData);
            }
        });

也许将所有这些变量收集到一个全局对象中是一个好主意,例如:

var globalVariables = {};
globalVariables.someVariable = 2;

这样您将拥有全局数据的一个入口点。

这就是我这样做的方式,很高兴听到其他人是如何做的。

I usually create global variables on the page and then just use them in js.
Something like:

//mypage.html

 <script type="text/javascript">
        var loadScansUrl = "<%=Url.Action<ReportScannerRunController>(controller => controller.LoadScans())%>";
        var loadInstancesUrl = "<%=Url.Action<ReportScannerRunController>(controller => controller.LoadInstances(-1))%>";
 </script>

Then I use them directly where I need.

//myfile.js

Ext.Ajax.request({
            url: loadInstancesUrl, // here is the usage!!!
            headers: {
                'Content-Type': 'application/json'
            },
            params: this.scanId,
            scope: this,
            success: function (response) {
                var result = Ext.decode(response.responseText);
                var comboData = [];
                Ext.each(result.Instances, function (instance) {
                    comboData.push({ Value: instance });
                });
                instances.store.loadData(comboData);
            }
        });

Perhaps it's a good idea to collect all this variables into one global object, like:

var globalVariables = {};
globalVariables.someVariable = 2;

So you'll have one entry point to your global data.

It's just the way I do this, nice to hear how other do.

始终不够 2025-01-13 10:39:54

您可以在 app/Configuration.js 中使用单例配置文件,在其中定义所有变量、用于全局访问的 url:

Ext.define('myApp.Configuration', {
        singleton : true,
        urls : { actionURL : /d.php, bgotUrl :abcd.php }
});

您现在需要在 Application.js 文件中需要此文件:
需要 : [ 'myApp.Configuration'] 提前加载它以便在其他文件中使用,例如:

myApp.Configuration.urls.actionURL

所以,我想对于您的应用程序范围设置来说是非常干净的解决方案。
干杯!

You can use a singleton Configuration file in app/Configuration.js , where u define all the variables , urls for global access :

Ext.define('myApp.Configuration', {
        singleton : true,
        urls : { actionURL : /d.php, bgotUrl :abcd.php }
});

you now need to require this file in Application.js file as
requires : [ 'myApp.Configuration'] to load it in advance for usage in other files like:

myApp.Configuration.urls.actionURL

So, i guess very clean solution for your application wide settings.
Cheers!

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