gpt4 book ai didi

javascript - ".."在 Meteor Spacebars 语句中做什么?

转载 作者:行者123 更新时间:2023-11-30 00:30:40 24 4
gpt4 key购买 nike

我有一个 handlebar 语句,它将用户 ID 传递给助手。我不确定这是如何工作的。 Handlebars {{#if isowner ..}} 有 .. 这里传递给辅助功能的参数是什么?

<template name="test">
...
<table class="table table-hover table-striped">
{{#each tester}}
<tr><
<td>{{#if isowner ..}}
<i class="fa fa-trash removeUser"></i>
{{/if}}
</td>
</tr>
{{/each}}
</table>
...
</template>


Template.test.helpers({
'isowner':function(parent){
return parent.userId === Meteor.userId();
}
});

显然,这仅在用户 ID 相同时才成立。 Meteor.userId() 是客户端的当前用户。那么将哪个用户标识传递给 parent?当然,这个名字不言而喻。它必须高出一个级别——但这在技术上是什么?去哪里?

最佳答案

.. 返回父(封闭)模板或结构的数据上下文——我装配了一个非常简单的 MeteorPad here您也许可以尝试一下,看看它是如何工作的。

在您的情况下,我认为它可能返回 test 模板的数据上下文。您可以在您的助手中使用 console.log(parent) 检查该对象并获取更多信息:

Template.test.helpers({
'isowner':function(parent){
console.log(parent);
return parent.userId === Meteor.userId();
}
});

您可以在 spacebars readme. 中找到有关如何解析 .. 以及如何使用它的更多信息。

关于javascript - ".."在 Meteor Spacebars 语句中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29675121/

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