如何使模板帮助者动态更改?骨干

发布于 2025-02-05 02:35:28 字数 237 浏览 3 评论 0原文

我的视图中有一个模板助手方法:

    templateHelpers() {
    
    return {
        url : this.model.get('url')
    };
}

我在模板中使用了URL变量;但是,仅在按钮点击时分配URL;因此,当呈现视图时,URL变量最初是未定义的。我该如何做到这一点,以便当实际分配URL时,模板助手变量还会更新到更新的URL变量?

I have a template helpers method in my view like so:

    templateHelpers() {
    
    return {
        url : this.model.get('url')
    };
}

And I use the url variable in my template; However, the URL only gets assigned on button click; So when the view is rendered, the URL variable is initially undefined. How can I make it so that when the url is actually assigned, the template helper variable also updates to the updated url variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹂绝世的画 2025-02-12 02:35:28

您说仅在按钮单击上分配URL,并且您希望该模板助手在分配时更新到更新的URL。

因此,如果我正确理解您,则解决方案很简单:

  1. 更改模板辅助功能定义并接受URL作为参数。
  2. 转到处理按钮点击事件的功能。
  3. 使用更新的URL调用模板辅助功能。
  4. 在模板辅助功能中使用该URL。

You say that url is only assigned on button click and you want that template helper updates to the updated url when it is assigned.

So, the solution is simple if I understand you correctly:

  1. Change template helper function definition and accept url as an argument.
  2. Go to the function where you handle button click event.
  3. Call template helper function with the updated url.
  4. Use that url in the template helper function.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文