最近,我已经从对模块使用单个JS文件转向使用RequireJS。不用说,我在该模块中使用了OpenLayers2。
我已经“需要”了Openlayers2,而要求JS就是不承认它的存在。
下面是我的代码示例:
require.config({
shim:{
openlayers: {
exports: 'OpenLayers'
}
},
paths: {
jquery: 'plugins/jquery/jquery.min',
openlayers: 'plugins/OpenLayers/OpenLayers'
}
});
require(['openlayers'], function(test) {
console.log('OL: '+test);
console.log('Vector' + test.Layer.Vector);
});第一个日志只返回一个null值。
第二个日志引发一个错误:Uncaught TypeError: Cannot read property 'Layer' of null。
有什么建议吗?
发布于 2014-07-09 06:18:35
所以我只是简单地使用了一个非常古老的版本的RequireJS..。所以这是我自己的错,哈哈,谢谢你的帮助比尔!
发布于 2014-07-08 14:59:45
奇怪的是,您遇到了这个问题,因为这在JSFiddle上运行得很好:
require.config({
shim:{
openlayers: {
exports: 'OpenLayers'
}
},
paths: {
jquery: 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min',
openlayers: 'http://www.openlayers.org/dev/OpenLayers'
}
});
require(['openlayers'], function(test) {
console.log('OL: '+ test);
console.log('Vector' + test.Layer.Vector);
});见此处:http://jsfiddle.net/FdL2S/
会不会是版本问题?您看到控制台中有什么错误吗?
https://stackoverflow.com/questions/24634707
复制相似问题