Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Coffeescript Meteorjs-从另一个模板中选择模板的DOM_Coffeescript_Meteor - Fatal编程技术网

Coffeescript Meteorjs-从另一个模板中选择模板的DOM

Coffeescript Meteorjs-从另一个模板中选择模板的DOM,coffeescript,meteor,Coffeescript,Meteor,我有以下几点 <div id="header"> {{> header}} </div> <div class="hidden content_box"> {{> content}} </div> 我不知道这是否是最好的方法,但在类似的情况下,我以前所做的是使用会话参数来存储div的显示/隐藏状态。在单击事件中,您只需要更改会话标志的值。在要显示/隐藏的div模板中,只需返回类名 JS中的示例: Template.h

我有以下几点

<div id="header">
    {{> header}}
</div>

<div class="hidden content_box">
    {{> content}}
</div>

我不知道这是否是最好的方法,但在类似的情况下,我以前所做的是使用会话参数来存储div的显示/隐藏状态。在单击事件中,您只需要更改会话标志的值。在要显示/隐藏的div模板中,只需返回类名

JS中的示例:

Template.header.events({
    "click button#display_content": function () {
        Session.set('contentShow', true);
    }
});

Template.content.className = function (input) {
    return Session.equals('contentShow', true) ? '' : 'hidden';
};
Html


是我,满足

您需要在
Meteor.startup()
中将会话标志初始化为false,例如
session.set('contentShow',false)。由于会话是被动的,当您更改会话标志时,div类名将自动重新计算。

Cool!谢谢那当然行。但它与传统的前端编码方式(我想我指的是通过jQuery和HTML进行编码的流行方式)有很大不同。喜欢听别人说什么,看看是否有其他选择。是的,对于您的用例来说非常复杂,在本例中,您可能只需在单击事件中执行
$('.display_content')。removeClass('hidden')
。模板只是占位符,它们不会插入到dom中,因此无法执行您建议的操作。对于复杂的用例,您必须以Meteor方式进行操作,例如,状态不能简单地通过onclick事件或标准jQuery/css选择器来更改。
<template name="content">
    It's me, content
</template>
Template.header.events "click button#display_content": (e) ->
  Template.content.show() ?????
Template.header.events({
    "click button#display_content": function () {
        Session.set('contentShow', true);
    }
});

Template.content.className = function (input) {
    return Session.equals('contentShow', true) ? '' : 'hidden';
};
<template name="content">
    <div class="{{className}} content_box">
        It's me, content
    </div>
</template>