【问题标题】:How to get data from calling page while in Ion Modal如何在离子模式中从调用页面获取数据
【发布时间】:2015-10-19 19:09:18
【问题描述】:

在我的一个页面上(其中有

<button class="button button-small button-balanced" data-ion-modal="reviewPopup">
    leave review
</button>

在那个模态中,我有一个表单,当我单击一个按钮时,应该将数据从模态和模板 a 的模板发送到服务器。我可以从 Modal 的表单中获取数据就好了,但我无法从调用页面访问任何数据(特别是我需要_id)。调用 Template.parentData 只会返回 null。

【问题讨论】:

    标签: javascript meteor ionic-framework meteor-blaze meteoric


    【解决方案1】:

    除了使用data-ion-modal="reviewPopup" 从模板中触发模态框外,您还可以从按钮事件中触发模态框,例如 -

    Template.templateName.events({
      'click #review-popup': function() {
         //capture data from parent template first
         //....
         var parentDataContext = {some data}
    
         IonModal.open("reviewPopup", parentDataContext);
      }
    })
    

    模态打开后,可以在模态助手中使用this访问父数据。

    【讨论】:

      【解决方案2】:

      我相信 Template.parentData(来自模态)将返回正文模板或特定于流星框架的另一个顶级模板。无论哪种方式, 如果您使用不同的框架,在其中专门将模态模板添加到页面的某个位置,我建议您将 _id 作为模板参数传入。

      但是据我所知,使用流星,你不能这样做 - 所以你可能必须使用具有全局范围的东西。

      如果您使用的是路由器,并且将 _id 作为路由的一部分,请从那里获取它(例如 FlowRouter.current().params )。

      或者只使用最简单的选项并使用 Session 变量。在 onRendered 函数中设置,在 Modal 的事件函数中访问它

      【讨论】:

        猜你喜欢
        • 2021-07-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-26
        • 1970-01-01
        • 2019-06-03
        相关资源
        最近更新 更多