Durandal Weyland / Requirejs optimizer with kendo ui dataviz

I am building an application with Durandal to connect with PhoneGap. When I try to start the weyland optimizer, I have some problems. The assembly and optimization are error-free (I use requirejs as an optimizer), but when I run the application, my kendo ui diagram throws an error "Uncaught TypeError: Object [object Object] does not have a method of" kendoChart ".

If I pause in debug mode in chrome where kendoChart is bound and type "kendo" in the console, I get kendoobject and can view its properties, etc., so it is definitely in the DOM.

Iv'e google quite a lot and found some topics here, but none of them seemed to sort my problem. For example, this stream or this .

I have a knockout binding for the chart below.

My weyland.config is as follows:

exports.config = function (weyland) {
weyland.build('main')
    .task.jshint({
        include: 'App/**/*.js'
    })
    .task.uglifyjs({
        // not uglyfying anything now...
        //include: ['App/**/*.js', 'Scripts/durandal/**/*.js', 'Scripts/custom/**/*.js']
    })
    .task.rjs({
        include: ['App/**/*.{js,html}', 'Scripts/custom/**/*.js', 'Scripts/jquery/*.js', 'Scripts/durandal/**/*.js'],
        exclude: ['Scripts/jquery/jquery-2.0.3.intellisense.js', 'App/main.js'],
        loaderPluginExtensionMaps: {
            '.html': 'text'
        },
        rjs: {
            name: 'main',
            baseUrl: 'App',
            paths: {
           'text': '../Scripts/text',
           'durandal': '../Scripts/durandal',
           'plugins': '../Scripts/durandal/plugins',
           'transitions': '../Scripts/durandal/transitions',

           'knockout': '../Scripts/knockout/knockout-2.3.0',
           'kendo': 'empty:', <-- tried refering kendo.all.min, or dataviz.chart or the path
           'jquery': '../Scripts/jquery/jquery-2.0.3.min',
           'Helpers': '../Scripts/custom/helpers',


                 ........ other scripts ......
            },
            deps: ['knockout', 'ko_mapping', 'command'],
            callback: function (ko, mapping, command) {
                ko.mapping = mapping;
            }
            //findNestedDependencies: true, **<-- tried both true and false here**
            inlineText: true,
            optimize: 'none',
            pragmas: {
                build: true
            },
            stubModules: ['text'],
            keepBuildDir: false,
            out: 'App/main-built.js'
        }
    });
 };
    // The custom binding for the kendo chart
define([
    'knockout',
    'jquery',
    'Helpers',
    'kendo/kendo.dataviz.chart.min'
    ], function (
    ko,
    $,
    helpers,
    kendoui
    ) {
    function drawChart(element, values, options) {
        $(element).kendoChart({ **<-- this is where I get an error**
            ... options for chart ...
        });
    }

// kendoUi data viz chart
ko.bindingHandlers.moodChart = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
        //set the default rendering mode to svg
        kendo.dataviz.ui.Chart.fn.options.renderAs = "svg";  **<-- this renders no errors**
        // if this is a mobile device
        if (kendo.support.mobileOS) {
            // canvas for chart for you!
            kendo.dataviz.ui.Chart.fn.options.renderAs = "canvas";
        }

        var values = ko.unwrap(valueAccessor());

        setTimeout(function () {
            drawChart(element, values);
        }, 125);
    }
};
});

I would add that everything works fine, working with non-optimized code in a web browser (or on the phone, for that matter).

I also tried faking the kendo path in the configuration file and adding a dependency to jquery, which really doesn't make any difference.

Any help would be appreciated!

+4
source share
1 answer

, , , . jquery, AMD. , . , jquery, script . NET-

 <body>
        <div id="applicationHost"></div>

        <script type="text/javascript" src="~/Scripts/jquery-1.9.1.js"></script>

        <script type="text/javascript" src="~/Scripts/whateverKendoVersionGoesHere.js"></script>

        <script type="text/javascript" src="~/Scripts/knockout-2.3.0.js"></script>
        <script type="text/javascript" src="~/Scripts/bootstrap.js"></script>

        <script type="text/javascript" src="~/Scripts/require.js" data-main="/App/main"></script>
    </body>

, jQuery . main.js define jquery knockout, Durandal (. main.js), Durandal AMD.

requirejs.config({
    paths: {
        'text': '../Scripts/text',
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'transitions': '../Scripts/durandal/transitions'
    }
});

define('jquery', function () { return jQuery; });
define('knockout', ko);

define(['durandal/system', 'durandal/app', 'durandal/viewLocator'],  function (system, app, viewLocator) {
   ...
});
+3

Source: https://habr.com/ru/post/1530623/


All Articles