【问题标题】:Difficulty using seperate template files in ember router with browserify在带有browserify的ember路由器中使用单独的模板文件有困难
【发布时间】:2014-07-27 19:56:58
【问题描述】:

我已按照本教程 http://kroltech.com/2013/12/boilerplate-web-app-using-backbone-js-expressjs-node-js-mongodb/ 设置我的后端 node.js 服务器,但我想尝试 ember,而不是使用骨干木偶作为前端。因此,在成功设置服务器后,我现在正在学习 ember http://emberjs.com/guides/getting-started/ 的本教程。

我遇到的问题是将外部模板包含在我的 ember 路由中。使用此代码和在浏览器中编写的待办事项模板,应用程序可以正常工作。

var Ember = require('ember');

window.Todos = Ember.Application.create();

Todos.Router.map(function() {
  this.resource('todos', { path: '/' });
});

但是,使用 ./templates/application.hbs 编写的模板并使用 browserify 进行尝试,

Todos.Router.map(function() {
  this.resource(require('./templates/application.hbs'), { path: '/' });
});

我收到如下所示的错误。

Uncaught TypeError: undefined is not a function myapp.js:46841
Error: Assertion Failed: The URL '/' did not match any routes in your application
    at new Error (native)
    at Error.Ember.Error (http://localhost:3300/js/myapp.js:12978:19)
    at Object.Ember.assert (http://localhost:3300/js/myapp.js:12141:11)
    at http://localhost:3300/js/myapp.js:47347:15
    at invokeCallback (http://localhost:3300/js/myapp.js:22081:19)
    at publish (http://localhost:3300/js/myapp.js:21751:9)
    at publishRejection (http://localhost:3300/js/myapp.js:22179:7)
    at http://localhost:3300/js/myapp.js:30448:7
    at Object.DeferredActionQueues.flush (http://localhost:3300/js/myapp.js:18195:24)
    at Object.Backburner.end (http://localhost:3300/js/myapp.js:18283:27) myapp.js:15589
Uncaught Error: Assertion Failed: Error: Assertion Failed: The URL '/' did not match any routes in your application 

我希望有人能阐明如何在 ember 路由器中包含外部模板。谢谢!

【问题讨论】:

标签: node.js ember.js browserify


【解决方案1】:

感谢您的调查!我认为我在解释我的问题时做得很差 - 我知道这是模板名称,但我不明白如何将其包含在我的应用程序中。我搜索了一下,发现grunt-ember-templates

为了将来参考,他们提供了非常好的文档来帮助您进行设置,这就是我的 emberTemplates 代码的样子。

emberTemplates: {
        compile: {
            options: {
                templateBasePath: 'client/src/templates'
            },
            files: {
                'build/templates.js': ['client/src/templates/*.hbs']
            }
        }
    },

然后我添加了'application' 作为我的路由模板名称。 不要忘记在您的应用构建中编译所有 build/。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-28
    • 2018-07-03
    • 2014-07-19
    • 1970-01-01
    • 2020-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多