使用 RequireJS 的 Mustache AMD 模块加载错误 [英] AMD Module Loading Error with Mustache using RequireJS

查看:25
本文介绍了使用 RequireJS 的 Mustache AMD 模块加载错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里关注教程:http://backbonetutorials.com/organizing-backbone-using-modules/ 而我想要做的就是在主干视图中使用 Mustache 而不是 underscore.js 作为我的模板引擎.一切都按预期工作,直到我尝试更换 Mustache.Firebug 给了我这个:

I am following the tuturoial here: http://backbonetutorials.com/organizing-backbone-using-modules/ and all I would like to do is use Mustache instead of underscore.js for my templating engine in a Backbone View. Everything is working as expected until I try to do the replacement of Mustache. Firebug gives me this:

模块加载超时:Mustache

我的 Mustache 包装器(在 libs/mustache/mustache-wrap.js 中)是这样的:

My Mustache wrapper (in libs/mustache/mustache-wrap.js) is like so:

define(['libs/mustache/mustache'], function(){
  // Tell Require.js that this module returns a reference to Mustache
  return Mustache;
});

这是我的主干视图的代码:

Here is the code for my Backbone View:

// Protocol Detail View
define([
  'jQuery',
  'Underscore',
  'Backbone',
  'Mustache',
  'collections/protocols',
  'text!templates/protocol/protocoldetail.html'
], function($, _, Backbone, Mustache, protocolCollection, protocolDetailTemplate){

    var protocolDetailView = Backbone.View.extend({

        el: "#asset-detail",
        render: function( pid ){
            this.collection = new protocolCollection;
            this.collection.fetch();
            var p = this.collection.getByCid('c'+pid);
            var template = "{{name}}";
            htmlr = Mustache.to_html(template, p);
            $(this.el).html(htmlr);
            //var compiledTemplate = _.template( protocolDetailTemplate, { protocol: protocol });
            //$(this.el).html(compiledTemplate);

        },

        events: {
            "submit #asset-owner": "chown"
        },

        chown: function ( pid ){
            console.log("Protocol Detail View chown callback.")
        }
    });

    return new protocolDetailView;
});

我的 main.js 文件具有以下配置:

My main.js file has the following config:

require.config({
    paths: {
      jQuery: 'libs/jquery/jquery',
      jQueryUI: '//ajax.aspnetcdn.com/ajax/jquery.ui/1.8.17/jquery-ui.min',
      jstree: 'libs/jstree/jquery.jstree',
      Mustache: 'libs/mustache/mustache-wrap',
      Underscore: 'libs/underscore/underscore',
      Backbone: 'libs/backbone/backbone'
  }
});

推荐答案

在你的 main.js 文件中,你有你需要的一切,确保将 Mustache 添加到配置中,不要担心包装器和直接尝试加载 Mustache.

In you main.js file where you have all you're requires, make sure to add Mustache to the config, and don't worry about the wrapper and just try loading Mustache directly.

require.config({ 
    'paths': { 
        "underscore": "libs/underscore", 
        "backbone": "libs/backbone",
        "Mustache": "libs/mustache/mustache"
    }
}); 

这可能有帮助...

此外,这里有一些入门应用程序可以帮助您完成您的需求和骨干之旅.

Also, here are some starter apps to help you out on your require, backbone journey.

https://github.com/jcreamer898/RequireJS-Backbone-Starter
https://github.com/david0178418/BackboneJS-AMD-Boilerplate
https://github.com/addyosmani/backbone-fundamentals
https://github.com/amdjs

这篇关于使用 RequireJS 的 Mustache AMD 模块加载错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆