elC*_*ano 3 javascript meteor semantic-ui
如果root-element是流星模板,则使用语义-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>
Run Code Online (Sandbox Code Playgroud)
并在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');
});
Run Code Online (Sandbox Code Playgroud)
错误是:
TypeError: $dimmer.on is not a function
semanti...27ec43c (Line 5786)
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?
作为模板的根元素不是问题.问题是BODY在模板中有标签.你结束了两个BODY标签,这导致有两个$调光器.因此,当调用$ dimmer.on时,它实际上是一个数组,而语义ui代码必须调用$ dimmer [i] .on(其中我将为0和1)并且它不会那样工作.
所以将hello.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>
Run Code Online (Sandbox Code Playgroud)
并创建一个布局(layout.html):
<head>
<title>Hello Error</title>
</head>
<body>
<h1>Reproduce error</h1>
{{> navigation}}
</body>
Run Code Online (Sandbox Code Playgroud)
这样可行.
当然你可以BODY从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>
Run Code Online (Sandbox Code Playgroud)
这也有效,但我认为第一种方法是清洁/流星方式.