【问题标题】:Return simple string to html form将简单字符串返回到 html 表单
【发布时间】:2015-12-08 02:33:20
【问题描述】:

这是我的 java 脚本代码...

if(vText != "" && vGerätenummer != "") {
        Tasks.insert({
          text: vText,
          gerätename: vGerätenummer,
          createdAt: vDatetime // current time
        });
      } else {
        Template.addObjects.helpers({
          'notification': function(){
            return "Bitte beide ausfüllen!";
          }
      })
}

我只想返回字符串“Bitte beide ausfüllen”,但是当我进入 else 子句时,html 中不会返回。

<template name="addObjects">
    <form class="form-horizontal" role="form">
        <div class="form-group">
            <input type="text" name="text" placeholder="Text" >
            <input type="text" name="gerätenummer" placeholder="Gerätenummer" >
            <input type="submit" value="Add Objects">
            <a>{{notification}}</a>
        </div>
    </form>
</template>

谢谢你...

【问题讨论】:

标签: javascript html string meteor return


【解决方案1】:

您应该在 else 块中使用会话变量 (http://docs.meteor.com/#/full/session)。例如

else {
        Session.set("notify", "true");
      })

然后在你的助手中,在 if 块之外定义,做类似的事情

Template.addObjects.helpers({
          'notification': function(){
            if (Session.get("notify") === "true"){
                return "Bitte beide ausfüllen!";
            }
          }});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    相关资源
    最近更新 更多