gpt4 book ai didi

ember.js - Ember js 中的正确模板名称约定:camelCase 与 Snake_case

转载 作者:行者123 更新时间:2023-12-02 18:54:37 25 4
gpt4 key购买 nike

我正在 ember js 中构建一个应用程序,以 Rails 作为后端(我正在使用 ember-rails gem),并且我正在努力寻找正确的方法来命名我的 Handlebars 模板。正确的约定是什么?例如:

我想对于路线 /user_profiles/4/ 我应该将我的模板放在 user_profiles/show.hbs 中,对吗?或者应该是userProfile/show.hbs

对于一个简单的模板来说也是如此,它应该是 user_menu.hbs 还是 userMenu.hbs (它们都适合我)。然而,为了用助手渲染它,我需要这样做:

{{render 'userMenu' }}

正确使用我的App.UserMenuController

那么我应该在任何地方都使用camelCase还是snake_case?或两者(文件夹名采用驼峰命名法,文件名采用蛇形命名法)

有人可以帮助我理解它,因为在 ember 指南中,大多数都是简单的名称,如 postscomments,所以很难理解。

最佳答案

I'm struggling with the correct way to name my handlebars templates. What is the correct convention?

大多数情况下,模板名称将与路由名称匹配。如果路由名称有 .将其替换为 /和隐蔽camelCase将名称路由至 under_scored模板名称。请参阅the naming conventions guide了解更多示例。

I imagine that for the route /user_profiles/4/ I should put my template in user_profiles/show.hbs right? Or should it be userProfile/show.hbs?

不确定您从哪里得到show.hbs 。由于模板基于路由名称(而不是 url),因此无法区分。假设您有这样的路线:

App.Router.map(function() {
this.route('user_profile', { path: '/user_profiles/:user_profile_id' });
});

路由名称是“user_profile”,因此 Ember.js 将查找这些对象:

  • App.UserProfileRoute
  • App.UserProfileController
  • user_profile模板

或者,您可以使用路线名称 userProfile ,其他一切都保持不变。

So Should I use camelCase every where or snake_case ?? or both (camelCase for folders and snake_case for filenames)

约定似乎是camelCase对于除模板路径(以及模板的文件夹名/文件名)之外的所有内容

关于ember.js - Ember js 中的正确模板名称约定:camelCase 与 Snake_case,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15367744/

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