【问题标题】:Yeoman auto-load modelsYeoman 自动加载模型
【发布时间】:2013-06-24 19:13:18
【问题描述】:

是否可以自动加载app/scripts/models 目录中的每个文件,还是我必须引用 index.html 中的每个文件?

我想为我的 Ember 应用程序创建一个每个文件的模型,这会产生很多行。不想写多余的代码。

【问题讨论】:

    标签: model ember.js autoload yeoman


    【解决方案1】:

    是的,这是可能的,如果您使用的是 yeoman(在最新版本中)并且您生成了一个 ember.js 应用程序:

    yo ember:all
    

    您应该在myproject/scripts/app.js 中有一个app.js,在顶部的文件中(从第10 行开始)您有以下代码行已注释:

    require('app/scripts/routes/*');
    require('app/scripts/controllers/*');
    require('app/scripts/models/*');
    require('app/scripts/views/*');
    

    取消注释它们,构建过程应该能够获取您的单个模型文件以及您在上面指定的目录中拥有的其他文件,如视图、控制器等。

    更新

    还值得一提的是,负责require 语句的是grunt 模块grunt-neuter,因此您应该将它也定义为Gruntfile.js 中的依赖项

    希望对你有帮助。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-23
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多