DataJS library not loading in RequireJS

此生再无相见时 提交于 2019-12-06 04:37:15

With requirejs I have this code:

<script type="text/javascript" src="0.1/Clientscripts/requirejs/2.1.11/require.js"></script>
<script type="text/javascript">
    requirejs.config({
        'baseUrl': '0.1/Clientscripts/',
        'paths': {
            'datajs':'datajs/1.1.2/datajs.min',
            'OData':'datajs/1.1.2/datajs.min'
        },
        'shim': {
            'OData':['datajs']
        }
    });
</script>

In my own module i did this:

define(['datajs','OData'], function (datajs,OData) {
    console.log(datajs);
    console.log(OData);
    console.log(OData.read);
}

Here the datajs and the OData objects are accessible.

Personaly I believe it's a bit awkward to have multiple 'paths'-entries to the same file..

It would have been cleaner if you could say:

'paths': { 'datajs':'path/to/datajs',...
 //and then
require(['datajs/core','datajs/OData'],...

But then again.. nothing is perfect :)

I think thats define([... instead of require([..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!