如何将json文件导入到TcHMI脚本中?

问题描述 投票:0回答:1

我的 TwinCAT HMI 项目中有 JSON 文件,我想在我的 HMI 脚本中使用它。该项目是基于打字稿的,但我认为它没什么相关性。 我尝试的是将

temperature-namings.json
文件放在 .ts 文件旁边,并在脚本中调用它:

import test = require("temperature-namings.json");
// or (also with ./ path prefix)
import test from "temperature-namings.json";

Build:Cannot find module 'temperature-namings.json' or its corresponding type declarations.

我尝试使用路径说明符,例如

..
,但智能感知不显示此文件。我的印象是它是过滤类型,因为 json 文件是脚本函数生态系统的一部分。所以我将我的json放入Imports中,但仍然无法导入它。

我还尝试将以下内容放入 tsconfig 文件中:

"resolveJsonModule": true,
"esModuleInterop": true,

但是随后又弹出另一个错误:

Build:Option '--resolveJsonModule' cannot be specified without 'node' module resolution

如何将 JSON 文件放入 TwinCAT HMI 项目中并从自定义 .ts 函数中读取内容?

typescript twincat twincat-hmi
1个回答
0
投票

TcHMI 版本 12.760.xx 之前不支持模块脚本。 JS 文件添加了简单的脚本/文本标签,而不是像

© www.soinside.com 2019 - 2024. All rights reserved.