所属产品: Mingcedar Studio DESIGNER
脚本里读取输入模板值:template.getValue(controlName) | Mingcedar Studio
输入模板用于收集值时,可通过 template.getValue() 读取当前输入。controlName 填输入模板实例名,不填 PLC Tag 名。
<section id="template-runtime" class="docs-block docs-block-intro docs-block-current"> <span class="section-kicker">方法</span> <h2>脚本里读取输入模板值:template.getValue(controlName)</h2> <p>输入模板用于收集值时,可通过 template.getValue() 读取当前输入。controlName 填输入模板实例名,不填 PLC Tag 名。</p> <div class="docs-detail-list"> <article id="template-runtime-item-1" class="docs-detail-row"> <strong>controlName 填什么</strong> <p>controlName 是当前页 Input 实例名或控件名,不是 Tag 名。匹配不区分大小写,名称应唯一。脚本参数加引号,如 template.getValue("Input Template")。</p> <pre class="docs-code-block"><code>var value = template.getValue("Input Template");
hqVisuDesigner.setComponentText("InputPreview", value);</code></pre> </article><article id="template-runtime-item-2" class="docs-detail-row"> <strong>template.getValue(controlName) 能做什么</strong> <p>先排除空白,再检查数字是否有限且在业务范围内:Number('') 为 0,Number.isNaN() 不能排除 Infinity。示例范围为 0~100,须按项目修改。</p> <pre class="docs-code-block"><code>var setpointText = template.getValue("Input Template");
var trimmed = String(setpointText == null ? "" : setpointText).trim();
var setpoint = Number(trimmed);
if (trimmed !== "" && Number.isFinite(setpoint) && setpoint >= 0 && setpoint <= 100) {
WriteTagDouble("PLC_LINE01.PUMP01.SETPOINT", setpoint);
}</code></pre> </article><article id="template-runtime-item-3" class="docs-detail-row"> <strong>适用场景</strong> <p>当输入模板只是采集值、不直接写 Tag,或需要先校验、转换、提交,或需要组合多个输入框值时,template.getValue() 就很关键。</p> </article><article id="template-runtime-item-4" class="docs-detail-row"> <strong>无需使用的场景</strong> <p>如果输入模板已经直接绑定 PLC Tag,且业务上不需要再做脚本判断,那很多时候不需要额外在脚本里读值。把事情交给配置完成,通常更可靠。</p> </article><article id="template-runtime-item-5" class="docs-detail-row"> <strong>使用边界</strong> <p>脚本里只使用手册写明的方法。不要推测模板底层结构,也不要将模板作为可任意遍历的普通对象处理。这样后续升级和交接更可控。</p> </article> </div> <div class="docs-note-grid"> <figure id="template-runtime-image-1" class="docs-note-card manual-doc-image-card"> <img src="/WEB_img/HQPPT/TemplateInstanceEditorFormInput.png" alt="模板编辑中的实例配置" loading="lazy" decoding="async"> <figcaption> <strong>模板实例配置</strong> <p>输入、按键和表格这三类模板,最终都应通过实例配置和公开方法来使用。</p> </figcaption> </figure> </div> </section>