首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EXTJS6.5:带有在Index.html中使用的变量的外部属性文件

EXTJS6.5:带有在Index.html中使用的变量的外部属性文件
EN

Stack Overflow用户
提问于 2019-07-03 15:05:36
回答 1查看 373关注 0票数 0

我有一个EXTJS6.5应用程序。我想在index.html中使用来自属性文件的变量。但是,更改这些变量的值应该不需要重新构建应用程序。这意味着如果需要,可以更改变量(不需要构建extjs代码)。

有人能帮个忙吗?

我已经看过了index.html可以使用占位符的其他线程,但似乎没有具体的例子。

这是我的属性文件(Runtime.js)

代码语言:javascript
复制
{
    "appUrl": "http://myappurl.com",
    "appId": "10"
}

Then I want to use these variables in my index.html as such:

这是我的index.html

代码语言:javascript
复制
<!DOCTYPE HTML>
<html lang="fr">

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=10, user-scalable=yes">
    <meta name="description" content="MyApp">

    <title>MyApp</title>

    <link rel="icon" type="image/png" href="myicon.png">
    <link rel="stylesheet" href="resources/dist/myapp-resources.min.css">
</head>

<body>
    <div id="myapp-app-loading">
        <div class="myapp-spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
    </div>

    <script type="text/javascript">
        var Ext = Ext || {};
        Ext.beforeLoad = function (tags) {
            Ext.manifest = 'classic'; // this name must match a build profile name
        };
    </script>

    <script src="Runtime.js"></script>

    <!-- The line below must be kept intact for Sencha Cmd to build your application -->
    <script id="microloader" data-app="6d7f3123-ffca-44d3-8ed2-14fr2w6be804" type="text/javascript" src="bootstrap.js"></script>
    <script src="{{Runtime.appUrl}}/configuration/MyConstants.js"></script>
    <script src="{{Runtime.appUrl}}/resources/mycharts/mycharts.js"></script>
    <script src="{{Runtime.appUrl}}/resources/ckeditor/ckeditor.js"></script>
</body>

</html>

这样行得通吗?或者请建议任何更好的方法来做this..thank你非常多。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-04 05:55:54

给定的Runtime.js文件存在语法错误。是无效的javascript文件。

Runtime.js应为:

代码语言:javascript
复制
window.appUrl="http://myappurl.com";
window.appId="10";

您可以在脚本块中使用这些变量,如window.appUrl/window.appid,而不是在html块中。

您可以采取解决方法来解决此问题:您可以从Runtime.js生成包含。示例:

index.html

代码语言:javascript
复制
<!DOCTYPE HTML>
<html lang="fr">

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=10, user-scalable=yes">
    <meta name="description" content="MyApp">

    <title>MyApp</title>

    <link rel="icon" type="image/png" href="myicon.png">
    <link rel="stylesheet" href="resources/dist/myapp-resources.min.css">
</head>

<body>
    <div id="myapp-app-loading">
        <div class="myapp-spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
    </div>

    <script type="text/javascript">
        var Ext = Ext || {};
        Ext.beforeLoad = function (tags) {
            Ext.manifest = 'classic'; // this name must match a build profile name
        };
    </script>

    <!-- The line below must be kept intact for Sencha Cmd to build your application -->
    <script id="microloader" data-app="6d7f3123-ffca-44d3-8ed2-14fr2w6be804" type="text/javascript" src="bootstrap.js"></script>
    <script src="Runtime.js"></script>
</body>

</html>

Runtime.js

代码语言:javascript
复制
window.appUrl="http://myappurl.com";
window.appId="10";

var script = document.createElement("script")
script.type = "text/javascript";
script.src = window.appUrl+"/configuration/MyConstants.js";

var script2 = document.createElement("script")
script2.type = "text/javascript";
script2.src = window.appUrl+"/resources/mycharts/mycharts.js";

var script3 = document.createElement("script")
script3.type = "text/javascript";
script3.src = window.appUrl+"/resources/ckeditor/ckeditor.js";

document.getElementsByTagName("body")[document.getElementsByTagName("body").length-1].appendChild(script);
document.getElementsByTagName("body")[document.getElementsByTagName("body").length-1].appendChild(script2);
document.getElementsByTagName("body")[document.getElementsByTagName("body").length-1].appendChild(script3);

2019-07-17更新:

如果你想在应用程序启动之前需要脚本,你必须在js块中的app.json中添加对脚本的引用(这是不能做的,因为你想个性化脚本源)。

第二个选项是在app.js中进行更改,您可以像这样执行Ext.Loader.loadScript

代码语言:javascript
复制
Ext.Loader.loadScript({
    url: 'my.js',
    onLoad: function(){
        Ext.application({
            name: 'Fiddle',
            extend: 'Fiddle.Application',
            autoCreateViewPort: false
        });
    },
    onError: function(){
        console.log('error');
    }
});`
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56864690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档