2

我正在使用Meteoric (Meteor + Ionic) 和 Iron。我的问题很简单,我找不到任何解决方案。

我有这个模板(离子+流星)

<!-- Header : Title -->
{{#contentFor "headerTitle"}}

  <h1 class="title">Geokaliz</h1>

{{/contentFor}}

<!-- Header : Button Right -->
{{#contentFor "headerButtonRight"}}

  {{#if isFocusedOnMarker}}
    <button class="button button-icon ion-ios-navigate" id="revoke-focus"></button>
  {{else}}
    <button class="button button-icon ion-ios-navigate-outline" id="become-focus"></button>
  {{/if}}

{{/contentFor}}

我想专注于#become-focus出现在我的页面上的按钮。它位于 Ionic 生成的页眉的顶部。

这是我在Meteor / Iron中的代码

Template.Home.events {

  "click #become-focus": (event) ->

    console.log('focused')
    Session.set('isFocusedOnMarker', true)

  "click #revoke-focus": (event) ->

    console.log('not-focused')
    Session.set('isFocusedOnMarker', false)

当我点击我的#become-focus按钮时,什么也没有发生,但是如果我将它移动到其他地方,比如说在我的页脚上,console.log就会触发它,这意味着它可以工作。

我的猜测是 Ionic 不接受头部的按钮,但我会觉得这很愚蠢。另一个想法是由于某种原因,标题不被认为是模板本身,但作为一个初学者,我完全不确定,也不知道如何解决这个问题。与我结构相似的人有一个想法吗?

编辑 如果这有帮助,这里是发现任何可能产生这个问题的代码的完整模板......

<template name="Home">

  <div class="home">

    <!-- Header : Title -->
    {{#contentFor "headerTitle"}}

      <h1 class="title">Geokaliz</h1>

    {{/contentFor}}

    <!-- Header : Button Right -->
    {{#contentFor "headerButtonRight"}}

      {{#if isFocusedOnMarker}}
        <button class="button button-icon ion-ios-navigate" id="revoke-focus"></button>
      {{else}}
        <button class="button button-clear" id="become-focus">
          {{> ionIcon icon="ios-navigate-outline"}}
        </button>
      {{/if}}

    {{/contentFor}}

    <!-- Map in the middle -->
    {{#ionContent class="has-header has-footer"}}

      {{>GeolocationMap}}

    {{/ionContent}}

    <!-- Footer : Target Setup -->
    {{#if myTarget.isActivated}}

      <!-- Revoke target button -->
      <div class="bar bar-balanced bar-footer">
        <div class="title title-center">
          <button class="button button-icon ion-checkmark-circled mini-margin" id="revoke-target"> You are a target</button>
        </div>
      </div>

    {{else}}

      <!-- Become target button -->
      <div class="bar bar-dark bar-footer">
        <div class="title title-center">
          <button class="button button-icon ion-close-circled mini-margin" id="become-target"> You are not a target</button>
        </div>
      </div>

    {{/if}}

  </div>

</template>
4

1 回答 1

0

{{#contentFor "headerButtonRight"}} 中的任何内容都将从您的模板中提取并注入到布局中,因此您需要在布局模板上附加事件。在您的情况下,也许您可​​以尝试将 Template.Home.events 替换为 Template.layout.events。

希望对你有效。

于 2015-12-29T13:31:04.353 回答