0

我正在尝试 使用我的流星项目加载 Dat-GUI: https ://github.com/dataarts/dat.gui。我在 client/lib 文件夹中添加了 dat-GUI 源代码。这是我的代码:

Template.EditorControllbar.rendered = function () {
    var controllBar = document.getElementById('controllbar'),
        gui, folder, controller;

    // Create GUI
    gui = new dat.GUI({autoPlace:false});
    controllBar.appendChild(gui.domElement);

    // Create folders
    var renderFolder = gui.addFolder('Render'),
    meshFolder = gui.addFolder('Mesh'),
    lightFolder = gui.addFolder('Light'),
    exportFolder = gui.addFolder('Export');

};

当我运行服务器时,我收到以下错误:

Exception from Deps afterFlush function function: ReferenceError: dat is not defined
    at Object.Template.EditorControllbar.rendered (http://localhost:3000/client/views/toons/toon_edit/editor_controllbar/editor_controllbar.js?5613eb3f7dfe2c5aed33925dfe2970dcc11a04b4:33:15)
    at http://localhost:3000/packages/ui.js?9419ac08328918a04e7a49464a988d45f851e1b0:439:23
    at _assign.flush (http://localhost:3000/packages/deps.js?4a82362ae66e863a1c1a8b0a5fec6f665e2038d1:348:13) debug.js:4

不过,相同的代码适用于 codepen: http ://codepen.io/praneybehl/pen/DabKv

有谁知道如何使用 Meteor 加载 Dat-GUI。任何帮助将不胜感激。

在此先感谢,普拉尼

4

1 回答 1

2

您添加了文件https://github.com/dataarts/dat.gui/blob/master/build/dat.gui.min.jsclient/lib?Meteor 会将所有 js-files 包装在一个函数中,因此 js-files 中的var-variables 不会在其他文件中可见,因此dat如果以这种方式添加文件,则无法使用该变量。相反,您需要在文件client/compatibility夹中添加文件。此文件夹中的 js-files 不会被包装在函数中,因此 var 变量将是一个全局变量,您可以在其他文件中使用它。

于 2014-07-18T17:52:41.283 回答