【问题标题】:Cordova/phonegap application with yeoman/backbone/handlebars/require带有 yeoman/backbone/handlebars/require 的 Cordova/phonegap 应用程序
【发布时间】:2013-07-21 09:50:23
【问题描述】:

我已尝试按照本教程进行操作:

使用 yeoman 和骨干开发我的测试 cordova 应用程序...我已按照所有步骤操作,但是当我尝试插入我的第一个视图时,控制台给了我有关模板的错误...我是这方面的新手我不明白我错在哪里。

如果我在我的应用程序源中执行代码,控制台错误是:

**GET http://localhost:8888/LABS_and_TRAINING/TEST/pgyo-test03/PgYoTest/src/app/scripts/templates.js 404 (Not Found) require.js:1880
Uncaught Error: Script error for: templates
http://requirejs.org/docs/errors.html#scripterror require.js:163**

如果我执行dist中的代码,错误是:

**Uncaught TypeError: Cannot call method 'template' of undefined** 

在这里你可以下载 src(没有节点模块) https://dl.dropboxusercontent.com/u/2637840/src.zip

【问题讨论】:

  • 您应该在问题中发布相关代码,而不是链接到 zip 文件。

标签: backbone.js requirejs handlebars.js yeoman


【解决方案1】:

查看 dist 构建时,我只收到“Cannot call method 'template' of undefined”错误。我遇到了解决方案,但不确定它为什么有效。

Handlebars 的 RequireJS Shim 应如下所示

shim: {
  handlebars: {
    exports: 'Handlebars',
    init: function() {
      this.Handlebars = Handlebars;
      return this.Handlebars;
    }
  }
}

这个解决方案是still being discussed,但现在可以使用。

【讨论】:

    【解决方案2】:

    问题是您的AppView-view 中的定义块,您尝试在其中加载一个名为templates 的文件。

    define([
        'jquery',
        'underscore',
        'backbone',
        'templates',// there is no file called templates
    ], function ($, _, Backbone, JST) {
        'use strict';
    

    这个文件不存在,所以你得到了 404。我假设你想加载 handlebars,而不是你在 requirejs.config 块中定义的。

    【讨论】:

    • 我认为templates.js 文件是grunt 在构建过程中生成的,在Gruntfile.js 中有一个handlebars 任务。现在,如果我将生成的 templates.js 从 .tmp/script/ 文件夹移动到 app/scripts 现在错误就像构建的应用程序:无法调用未定义的方法“模板”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 2014-07-02
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多