meteor - 基础模态事件不起作用

标签 meteor zurb-foundation

我的代码

{{#with profile}}

        {{> foundation}}
{{/with}}


<template name="foundation">
    <div id="userprofile" class="reveal-modal" data-reveal>
         <h2 id="selectedProfileName">{{name}}</h2>
        <div class="large-12 columns paddingtop">
            <div class="large-3 columns">
                <img id="selectedProfilePicture" src="{{picurl}}" />
                <p id="selectedProfileLink" ><a href="/accounts/profile/{{_id}}" >Open Profile</a></p>
            </div>
        </div>
        <div class="columns right">
            <div id="btnCancel" class="btnCancel button button-register small">Cancel</div>
            <div id="btnConfirm" class="btnConfirm button button-register small" data={{_id}}>Okay</div>
        </div>      
        <a class="close-reveal-modal">&#215;</a>
    </div>
</template>

我正在使用 JS 打开模式
$("#userprofile").foundation("reveal","open");

我的事件是
Template.foundation.events({
    'click .btnConfirm':function(evt){
        console.log("confirm");
        $('#curator_name').val("");
        $('#confirmationText').html("");
    },
    'click .btnCancel':function(){
        console.log("close");

    },
});

他们没有开火,任何人都面临同样的问题。

我试图将所有模式代码放在父模板中并绑定(bind)事件,这也不起作用

最佳答案

很有可能,像 Semantic-UI 和其他一些框架一样,Foundation modals 被从 DOM 中删除并以编程方式添加到其他地方(比如在正文的末尾)。如果是这种情况,则在封闭模板上注册的事件处理程序将不再能够找到它们。

解决方案是在您的模式中定义一个模板,并将事件附加到该模板。就像是:

<template name="foundation">
  <div id="userprofile" class="reveal-modal" data-reveal>
    {{> foundationInner}}  
  </div>
</template>

<template name="foundationInner">
  <h2 id="selectedProfileName">{{name}}</h2>
  <div class="large-12 columns paddingtop">
    ...
  </div>      
  <a class="close-reveal-modal">&#215;</a>
</template>

然后在 foundationInner 上注册所有事件处理程序(相对于其父 View 不会移动)。

当然,如果在 Foundation 中没有发生分离和重新连接,那么这完全是另外一回事。更多关于这个问题 here .

关于meteor - 基础模态事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27194160/

相关文章:

mongodb - Meteor + Mongodb : is there a way to fully exclude some subdocuments from db. find() 的结果?

javascript - meteor 铁路由器 : Passing data between routes

css - 如何在 Foundation 5 Nav 中添加圆底 Angular 以下拉

javascript - 使用wrapAsync 将 Twilio Node 客户端包装在 Meteor 应用程序中失败

javascript - 铁路由器: Meteor JS

c# - 基础模态内的 asp 按钮事件未触发

html - CSS:如何在不设置固定高度的情况下使背景图像出现在 div 中

javascript - 关闭 Zurb Foundation 5 元标记

html - 小屏幕上的源排序列

javascript - api调用返回undefined后的Meteor方法