本文介绍了正确的模板名称约定在ember js camelCase vs snake_case的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在建立一个应用程序在ember js与rails作为后端(我正在使用ember-rails gem),我正在努力使用正确的方式来命名我的手柄模板。什么是正确的惯例?例如: 我想像对于路由 / user_profiles / 4 / 我应该把我的模板放在code> user_profiles / show.hbs 对吧?或者应该是 userProfile / show.hbs ? 相同的简单模板,应该是 user_menu.hbs 或 userMenu.hbs (他们都为我工作)。但是为了使用我需要做的帮助器: {{render'userMenu'}} 使用我的App.UserMenuController 所以我应该使用camelCase每个地方或snake_case?或者两者(文件夹的camelCase和文件名的snake_case) 有人可以帮助我了解它,因为在ember指南中,大多数简单的名称,如帖子或评论所以很难理解。解决方案 大多数时候,模板名称将匹配路由名称。如果路由名称具有。将其替换为 / 并隐藏 camelCase 路由名称到 under_scored 模板名称。有关更多示例,请参阅命名约定指南。不知道你在哪里得到 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 ,其他一切都会保持不变。约会似乎是 camelCase 除模板路径(以及模板的文件夹名/文件名)之外的所有内容 I'm building an app in ember js with rails as backend(I am using the ember-rails gem) and I'm struggling with the correct way to name my handlebars templates. What is the correct convention? For example: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?Same for a simple template, should it be user_menu.hbs or userMenu.hbs (both of them are working for me). However in order to render it with the helper i need to do :{{render 'userMenu' }}to use right my App.UserMenuControllerSo Should I use camelCase every where or snake_case ?? or both (camelCase for folders and snake_case for filenames)Can someone help my to understand it since in ember guides the are mostly simple names like posts or comments so it is hard to understand. 解决方案 Most of the time the template name will match the route name. If route name has a . replace it with a / and covert camelCase route names to under_scored template names. See the naming conventions guide for more examples.Not sure where you are getting show.hbs. Since template is based on route names (not urls) it is impossible to tell. Let's assume you've got routes like this:App.Router.map(function() { this.route('user_profile', { path: '/user_profiles/:user_profile_id' });});The routes name is "user_profile" so Ember.js will look for these objects:App.UserProfileRouteApp.UserProfileControllerthe user_profile templateAlternatively you could use a route name of userProfile, everything else would stay the same.Convention seems to be camelCase for everything but template paths (and thus template's foldername/filename) 这篇关于正确的模板名称约定在ember js camelCase vs snake_case的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-23 07:07