【问题标题】:Populating a text box with parameter in meteor iron router在流星铁路由器中填充带有参数的文本框
【发布时间】:2016-10-13 09:49:24
【问题描述】:

所以我有一个这样设置的流星路线:

Router.route('/joinRoom/:_id', function () {   
       this.render('joinRoom');
});

还有一个简单的html模板:

<template name="joinRoom">
   <p>Enter Your Room ID</p>
   <input placeholder="1" type="text" class="joinID">
   <button class="submit" type="submit" value="submit">Join Room -></button>
</template>

我想将作为_id 参数传入的数据填充为&lt;input&gt; 中的文本。

我尝试查看 Iron Router 的文档,但无法弄清楚。我该怎么做?

【问题讨论】:

    标签: javascript node.js meteor iron-router


    【解决方案1】:

    你可以在你的助手中使用Router.current().params从url中获取参数。

    <input placeholder="1" type="text" class="joinID" value={getId}>
    

    助手:

    getId: function () {
      var params =  Router.current().params;
      return params && params._id ? params._id : '';
    }
    

    【讨论】:

      【解决方案2】:

      您可以通过以下方式将数据从后端发送到模板。

      this.render('joinRoom', {id :this.params._id});
      

      而在模板上,可以通过以下方式实现。

      <input value={{ id }} />
      

      【讨论】:

        猜你喜欢
        • 2014-03-02
        • 2014-09-03
        • 2014-06-20
        • 1970-01-01
        • 2014-10-12
        • 1970-01-01
        • 1970-01-01
        • 2015-08-11
        • 1970-01-01
        相关资源
        最近更新 更多