2013-01-09 44 views
1

將mustache.js加載爲RequireJS的AMD模塊(用於Backbone模型中)時遇到問題。我也開始使用TypeScript,因此我不完全遵循依賴和聲明的流程!將Mustache加載爲具有RequireJS的AMD模塊 - 未定義小鬍子

與app.ts開始:

require.config({ 
    paths: {'jquery': 'lib/jquery-1.8.3.min', 'underscore': 'lib/underscore.min', 'backbone': 'lib/backbone.min', 'mustache': 'lib/mustache', 'appmain': 'AppMain'}, 
    shim: {mustache: { deps: ["jquery"] }, backbone: { deps: ["underscore", "jquery"] }, appmain: {deps: ["backbone", "mustache"] } } }); 

require(['appmain'], (main) => { 
    var appMain = new main.AppMain(); 
    appMain.run(); 
}); 

appmain.ts:

import tm = module("models/TestModel"); 

export class AppMain { 
    public run() { 
     var testModel = new tm.TestModel() 
    } 
} 

TestModel.ts:

/// <reference path="../modules/backbone.d.ts"/> 
export class TestModel extends Backbone.Model { 
    constructor(options?) { 
     super(options); 
    }; 
    initialize() { 
     var stringTemplate = "{{something}}"; 
     Mustache.compile(stringTemplate); 
    }; 
} 

我得到一個JavaScript錯誤說「沒有定義鬍子「,儘管mustache.js確實在TestModel.js之前被加載。我只是從這裏使用了mustache.js:https://github.com/janl/mustache.js,所以我想我可能不明白AMD模塊是如何正確聲明的。

我看到有一些「AMD包裝」作爲這個項目的一部分,但我似乎無法弄清楚它們是如何使用的。

+0

你的鬍子墊片需要輸出東西 – chchrist

+0

鬍鬚不依賴於jQuery –

回答

2

鬍子呢define itself as an AMD module,所以它並不需要進行勻。我不知道TypeScript以及它如何與RequireJS集成,但是嘗試從配置的墊片陣列中刪除鬍子。