最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to include a .js file in another .js file when working with QML and QtQuick2? No browser involved - Stack Overf

programmeradmin1浏览0评论

In order to include one .js file in another .js file I tried writing the following in a .js file.

var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'helper.js';
head.appendChild(script);

I got the error: ReferenceError: document is not defined

Then I wrote:

<script type="text/javascript" charset="utf-8">
   $(documuent).ready(function () { var editChange = $('td').replaceWith('<td id = "@Html.ValueFor(x => x.name)" >'); });
</script>

on the top of it, but got the error: SyntaxError: Unexpected token <

Problem is that here no browser is involved. This .js file is working along QML and getting piled with qmake.

What is the syntax for this?

In order to include one .js file in another .js file I tried writing the following in a .js file.

var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'helper.js';
head.appendChild(script);

I got the error: ReferenceError: document is not defined

Then I wrote:

<script type="text/javascript" charset="utf-8">
   $(documuent).ready(function () { var editChange = $('td').replaceWith('<td id = "@Html.ValueFor(x => x.name)" >'); });
</script>

on the top of it, but got the error: SyntaxError: Unexpected token <

Problem is that here no browser is involved. This .js file is working along QML and getting piled with qmake.

What is the syntax for this?

Share Improve this question edited Sep 10, 2020 at 12:36 NG_ 7,2018 gold badges49 silver badges69 bronze badges asked Jul 28, 2014 at 8:27 Aquarius_GirlAquarius_Girl 23k71 gold badges249 silver badges441 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Here is the documentation on "Importing JavaScript Resources in QML" with the specific case of importing in another JS file

If you have a file helper.js and you want to use its functions in another javascript file you can do like that:

.import "helper.js" as Helper

Then you can use one of its functions like this:

Helper.myFunction();

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论