gpt4 book ai didi

javascript - Meteor/Semantic-UI 中的错误?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:45:01 25 4
gpt4 key购买 nike

如果根元素是 meteor 模板,语义 ui 模态窗口的使用将不起作用:

包:semantic-ui-css

错误重现:

你好.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)

有人知道怎么解决吗?

最佳答案

作为模板的根元素不是问题。问题是模板中有 BODY 标签。您最终得到两个 BODY 标签,这导致有两个 $dimmers。因此,当调用 $dimmer.on 时,它实际上是一个数组,语义 ui 代码必须调用 $dimmer[i].on(其中 i 将是 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>

并创建布局 (layout.html):

<head>
<title>Hello Error</title>
</head>

<body>
<h1>Reproduce error</h1>
{{> navigation}}
</body>

有效。

当然你可以从 hello.html 中删除 BODY 标签:

<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>

这也行,但我认为第一种方法是 clean/Meteor 方式。

关于javascript - Meteor/Semantic-UI 中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30373124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com