gpt4 book ai didi

kendo-ui - Durandal Weyland/Requirejs 优化器与 kendo ui dataviz

转载 作者:行者123 更新时间:2023-12-02 19:58:28 24 4
gpt4 key购买 nike

我正在使用 Durandal 构建一个应用程序以与 PhoneGap 捆绑在一起。当我尝试运行 weyland 优化器时,我遇到了一些问题。构建和优化运行良好,没有任何错误(我使用 requirejs 作为优化器),但是当我运行应用程序时,我的 kendo ui 图表会抛出一个错误,指出“Uncaught TypeError: Object [object Object] has no method 'kendoChart'”。

如果我在 chrome 中暂停 Debug模式(其中发生 kendoChart 绑定(bind))并在控制台中输入“kendo”,我会得到 kendoobject 并可以查看其属性等,因此它肯定在 DOM 中。

我在谷歌上搜索了很多,并在此处找到了一些线程,但似乎没有一个能解决我的问题。例如this threadthis one .

我有一个图表的自定义剔除绑定(bind),如下所示。

我的 weyland.config 看起来像这样:

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);
}
};
});

我可能会补充一点,在网络浏览器(或手机)中运行未优化的代码一切正常。

我还尝试在配置文件中填充 kendo 路径并添加对 jquery 的依赖项,这似乎没有任何区别。

如有任何帮助,我们将不胜感激!

最佳答案

对于像剑道这样的大型框架,它们有自己的一组依赖项,例如jquery 版本,我倾向于不将它们与我自己的 AMD 模块捆绑在一起。个人喜好,我知道。看看如何通过 .NET example 中的普通脚本标签加载 jquery 、 Knockout 和 kendo 。

 <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和knockout就会作为全局变量加载。在 main.js 中,您必须定义 jqueryknockout 才能使它们可供 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) {
...
});

关于kendo-ui - Durandal Weyland/Requirejs 优化器与 kendo ui dataviz,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22252949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com