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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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
Meteor 获取流星模板的外部上下文_Meteor - Fatal编程技术网

Meteor 获取流星模板的外部上下文

Meteor 获取流星模板的外部上下文,meteor,Meteor,我有以下用例:有些房间里面有床。(糟糕…) 有一个房间循环,它使用一个模板“房间” 基本上我不想写{{getBeds this}},但是只有{{getBeds}这不应该工作吗 Template.room.getBeds = function () { if (this.guests_id) return this.beds - _.size(this.guests_id); else return this.beds; }; 见: 帮助程序可以获

我有以下用例:有些房间里面有床。(糟糕…)

有一个房间循环,它使用一个模板“房间”

基本上我不想写{{getBeds this}},但是只有{{getBeds}

这不应该工作吗

Template.room.getBeds = function () {
    if (this.guests_id)
        return this.beds - _.size(this.guests_id);
    else
        return this.beds;
};
见:

帮助程序可以获取参数,并在
中接收当前模板数据:


嗨,拉胡尔,这个很好用!我可以问一个后续问题吗?我还有Template.room.getFreeBeds=function(room){return}.range(Template.room.freeBeds(room));};根据之前的数据。我是否可以从外部设置此函数?或者是否有更好的地方可以使用以数据为中心的getBeds()函数?
<template name="room">
<div class="room-outer">
    <button type="button" class="btn" data-toggle="collapse" data-target="#list-{{_id}}">
        {{name}} : {{getBeds this}} beds free.
    </button>
    <div id="list-{{_id}}" class="collapse in room-inner">
        {{#each guests_id}}
            <div class="bed">
                <div class="blanket">
                {{showUser this}}
                </div>
            </div>
        {{/each}}
    </div>
</div>
</template>
Template.room.getBeds = function (room) {
    if (room.guests_id)
        return room.beds - _.size(room.guests_id);
    else
        return room.beds;
};
Template.room.getBeds = function () {
    if (this.guests_id)
        return this.beds - _.size(this.guests_id);
    else
        return this.beds;
};