流星/语义UI中的错误?

时间:2015-05-21 11:59:25

标签: javascript meteor semantic-ui

如果根元素是流星模板,则使用语义模式窗口不起作用:

包:semantic-ui-css

错误再现:

hello.html的:

<template name="hello">
    <head>
        <title>Hello Error</title>
    </head>

    <body>
    <h1>Reproduce error</h1>

    {{> navigation}}

    <div class="delete openModal">OPEN<i class="close icon"></i></div>

    <div id="modalView" class="ui modal">
        <div class="content">
            <div class="ui fluid input">
                Modal Error Test
            </div>
        </div>
        <div class="actions">
            <div class="ui button cancel">Cancel</div>
            <div class="ui button ok">OK</div>
        </div>
    </div>
    </body>
</template>

<template name="navigation">
    <div class="ui menu">
        <a class="item" id="home" href="/">
            <i class="home icon"></i> welcome
        </a>


    </div>

</template>

在Javascript(hello.js)代码中:

if (Meteor.isClient) {
  Template.hello.events({
    'click .openModal': function (event,template) {
      $('#modalView')
          .modal({
            onDeny    : function(){
              console.log('canceled');
            },
            onApprove : function() {
              console.log("yeah!");
            }
          })
          .modal('show')
      ;
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}

Router.route('/', function () {
    this.render('hello');
});

错误是:

TypeError: $dimmer.on is not a function
semanti...27ec43c (Line 5786)

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:6)

作为模板的根元素不是问题。问题是模板中有BuildConfig标记。你结束了两个BODY标签,这导致有两个$ dimmers。因此,当调用$ dimmer.on时,它实际上是一个数组,语义ui代码必须调用$ dimmer [i] .on(其中我将为0和1)并且它不会那样工作

所以将hello.html更改为:

BODY

并创建一个布局(layout.html):

<template name="hello">
    <div class="delete openModal">OPEN<i class="close icon"></i></div>

    <div id="modalView" class="ui modal">
        <div class="content">
            <div class="ui fluid input">
                Modal Error Test
            </div>
        </div>
        <div class="actions">
            <div class="ui button cancel">Cancel</div>
            <div class="ui button ok">OK</div>
        </div>
    </div>
</template>

<template name="navigation">
    <div class="ui menu">
        <a class="item" id="home" href="/">
            <i class="home icon"></i> welcome
        </a>
    </div>
</template>

有效。

当然,您只需从hello.html中删除<head> <title>Hello Error</title> </head> <body> <h1>Reproduce error</h1> {{> navigation}} </body> 标记:

BODY

这也有效,但我认为第一种方法是清洁/流星方式。