gpt4 book ai didi

javascript - 在 Meteor 的 onRendered 中获取模板变量

转载 作者:行者123 更新时间:2023-11-30 16:28:02 26 4
gpt4 key购买 nike

我有一个模板 settings,其中有一个自动表单。

我在 onRendered 函数中为我的自动窗体添加了一个钩子(Hook)

Template.settings.onRendered( () => {
AutoForm.addHooks( 'editForm', {
onSuccess: function( formType, result ) {
//
}
} );
} );

如何在我的 onSuccess 中通过 Template.settings.helpers 获取模板中填充的变量?

我试过 Template.instance().variableName,但找不到。

最佳答案

来自 Meteor 文档:

In the body of a callback, this is a template instance object that is unique to this occurrence of the template and persists across re-renderings. Use the onCreated and onDestroyed callbacks to perform initialization or clean-up on the object.

http://docs.meteor.com/#/full/template_onRendered

但我认为您需要使用 function 而不是 ES2015 箭头函数,否则 this 将不会像预期的那样。

此外,您还需要添加以下行:
常量 self =这个;
然后,如果您想在 Autoform 函数中访问它,请使用 self

关于javascript - 在 Meteor 的 onRendered 中获取模板变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33804242/

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