<i class="主页图标"></i>欢迎</a>模板>
在 Javascript (hello.js) 代码中:
if (Meteor.isClient) {Template.hello.events({'点击 .openModal':函数(事件,模板){$('#modalView').modal({拒绝:函数(){console.log('取消');},onApprove :函数(){console.log("是的!");}}).modal('显示');}});}如果(流星.isServer){流星.启动(函数(){//启动时在服务器上运行的代码});}Router.route('/', function () {this.render('你好');});
错误是:
TypeError: $dimmer.on 不是函数语义...27ec43c(第5786行)
有人知道如何解决这个问题吗?
解决方案
作为模板的根元素不是问题.问题在于模板中有 BODY
标签.您最终会得到两个 BODY
标签,这导致有两个 $dimmers.所以当 $dimmer.on 被调用时,它实际上是一个数组,语义 ui 代码必须调用 $dimmer[i].on(其中 i 是 0 和 1),它不会那样工作.
因此将 hello.html 更改为:
<div class="delete openModal">OPEN<i class="关闭图标"></i></div><div id="modalView" class="ui modal"><div class="内容"><div class="ui 流体输入">模态错误测试<div class="actions"><div class="ui button cancel">Cancel</div><div class="ui button ok">OK</div>
模板><模板名称=导航"><div class="ui menu"><i class="主页图标"></i>欢迎</a>模板>
并创建一个布局(layout.html):
<title>你好错误</title>头部><身体><h1>重现错误</h1>{{>导航}}
那行得通.
当然,您可以从 hello.html 中删除 BODY
标签:
<头><title>你好错误</title>头部><h1>重现错误</h1>{{>导航}}<div class="delete openModal">OPEN<i class="关闭图标"></i></div><div id="modalView" class="ui modal"><div class="内容"><div class="ui 流体输入">模态错误测试<div class="actions"><div class="ui button cancel">Cancel</div><div class="ui button ok">OK</div>
模板><模板名称=导航"><div class="ui menu"><i class="主页图标"></i>欢迎</a>模板>
这也行,但我认为第一种方法是 clean/Meteor 方法.
the usage of a semantic-ui modal window does not work if the root-element is a meteor template:
package: semantic-ui-css
Error reproduction:
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>
And in Javascript (hello.js) code:
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');
});
The error is:
TypeError: $dimmer.on is not a function
semanti...27ec43c (Line 5786)
Does anyone know how to solve this?
解决方案
The root element being a template is not the problem. The problem is having the BODY
tag in the template. You wind up with two BODY
tags, which leads to having two $dimmers. So when $dimmer.on is called, it is actually an array and the semantic-ui code would have to call $dimmer[i].on (where i would be 0 and 1) and it doesn't work that way.
So change hello.html to:
<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>
And create a layout (layout.html):
<head>
<title>Hello Error</title>
</head>
<body>
<h1>Reproduce error</h1>
{{> navigation}}
</body>
That works.
Of course you could just remove the BODY
tag from hello.html:
<template name="hello">
<head>
<title>Hello Error</title>
</head>
<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>
</template>
<template name="navigation">
<div class="ui menu">
<a class="item" id="home" href="/">
<i class="home icon"></i> welcome
</a>
</div>
</template>
That works too, but I think the first approach is the clean/Meteor way.
这篇关于Meteor/Semantic-UI 中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文