【问题标题】:How to pass a dynamic parameter in option in Meteor?如何在 Meteor 的选项中传递动态参数?
【发布时间】:2017-03-30 08:48:24
【问题描述】:

我在 Meteor 上使用 Jade。

我想使用 option 关键字将动态参数传递给函数, 但我收到以下错误:

play.jade:Jade 语法错误:预期标识符、数字、字符串、布尔值、null 或包含在“(”、“)”中的子表达式 {{.}}

见下面我的代码,myInput 函数返回任意值,这些值是列表框的值,测试函数应该打印选择的值。

在play.jade:

select(id="input"
name="select"
value="a"
style="border-right-color: #c0c0c0 !important;"
type="text")
  each myInput
    <option {{testing #{.}}}>#{.}</option>

在 play.js 中:

myInput = function() {
    var myArray = ["ABC", "123", "DEF"];
    return myArray;
};

testing: function(param) {
    console.log(param);
}

【问题讨论】:

  • 你能解释一下吗? &lt;option {{testing #{.}}}&gt;#{.}&lt;/option&gt;我感觉无法解决&lt;option {{ }} &gt;中的其他车把@
  • {{testing}} 是我想要在单击列表框时调用的辅助函数。 #{.} 是每次交互中每个语句传递的值,我将它用作测试函数的参数。如果我只写 或 {{testing "parameter"}}>#{.} 效果很好

标签: javascript meteor pug


【解决方案1】:

您可以将其传递给函数,这将是您从数组中获取的值。

In play.jade:

select(id="input"
name="select"
value="a"
style="border-right-color: #c0c0c0 !important;"
type="text")
  each myInput
    <option +testing(this)>+this</option>

【讨论】:

    猜你喜欢
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 2020-02-15
    • 1970-01-01
    • 2013-02-04
    相关资源
    最近更新 更多