问题描述
一直在一个系统上的异步加载文档特定的脚本到一个流星模板,它被渲染后:
Been working on a system to load document-specific scripts asynchronously into a Meteor template after it's been rendered:
Template.postPage.onRendered(function(){
var post = Template.currentData();
if(post.libs) post.libs.forEach(function(e){
console.log(e);
$.getScript(e, function(data, text, code){
console.log(text);
}).done(threejs);
function threejs(){
var scene = new THREE.Scene();
};
});
});
此模式适用于宪章,Chart.js,和D3,但似乎并没有被用的其他库 - 所有都可以在全球范围,但我似乎无法找到三
通过three.js随时随地构造的对象。
This pattern works with Chartist, Chart.js, and d3 but doesn't seem to be working with three.js—all of the other libraries are available globally, but I can't seem to find the THREE
object constructed by three.js anywhere.
我失去了一些东西很明显,或者我只需要包装three.js的内容,一个匿名函数初始化?如果是的话,可能会有人提供一个例子/上的文档怎么才能做到最好?
Am I missing something obvious, or do I just need to wrap the contents of three.js in an anonymous function to initialise? If so, could someone provide an example/documents on how best to do so?
更新:我难倒。通过切换到一个CDN,三
负荷非常清楚。为了自给自足,我想从我自己的托管服务器,如果任何人都可以提出任何额外的测试,我很乐意听到他们的声音。
Update: I'm stumped. By switching to a CDN, THREE
loads perfectly well. For the sake of self-sufficiency I'd like to host from my own server—if anyone can recommend any additional tests, I'd love to hear them.
推荐答案
终于想通了这一点,为自己的项目 - 使这项工作的方法是编辑 three.min.js
源文件。
Finally figured this out for my own project - the way to make this work is to edit the three.min.js
source file.
删除/评论使用严格;
在 three.min.js
开始让它正确加载。
Removing/commenting 'use strict';
at the start of three.min.js
lets it load correctly.
这似乎与流星的以下功能/问题:的https:// github上。 COM /流星/流星/问题/ 1380
This seems to be related to the following feature/issue of meteor: https://github.com/meteor/meteor/issues/1380
在CDN很可能未缩小的,并没有包含使用严格;
。为了安全起见,使用严格;
或许应该被放在全球的三
命名空间已被宣布之后。
The CDN was likely un-minified and didn't contain 'use strict;'
. To be safe, 'use strict;'
should probably be placed after the global THREE
namespace has been declared.
这篇关于通过加载阿贾克斯后找不到three.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!