【问题标题】:Node.js Express App - Rickshaw.Graph.RangeSlider TypeError: $(element).slider is not a functionNode.js Express App - Rickshaw.Graph.RangeSlider TypeError: $(element).slider is not a function
【发布时间】:2014-07-08 03:03:04
【问题描述】:

这是与Rickshaw.Graph.RangeSlider TypeError: $(element).slider is not a function类似的问题

不同之处在于我在使用 Express 框架的 node.js 应用程序中使用 Rickshaw。

我收到错误消息:“TypeError: $(element).slider is not a function”。 (第 2 行)

我在 package.json 文件夹中指定 jquery-ui ("^1.10.5") 作为依赖项。 执行“npm install”并查看 node_modules 文件夹中的 jquery-ui 文件夹。 我不确定为什么它在下面的上下文中丢失,然后导致错误。

$( function() {
$(element).slider( {

    range: true,
    min: graph.dataDomain()[0],
    max: graph.dataDomain()[1],
    values: [ 
        graph.dataDomain()[0],
        graph.dataDomain()[1]
    ],
    slide: function( event, ui ) {

        graph.window.xMin = ui.values[0];
        graph.window.xMax = ui.values[1];
        graph.update();

        // if we're at an extreme, stick there
        if (graph.dataDomain()[0] == ui.values[0]) {
            graph.window.xMin = undefined;
        }
        if (graph.dataDomain()[1] == ui.values[1]) {
            graph.window.xMax = undefined;
        }
    }
} );

});

更新:

也许我需要使用 Grunt 构建系统?

构建 jQuery UI

jQuery UI 使用 Grunt 构建系统。

要构建 jQuery UI,你必须安装 node.js 然后运行 以下命令:

安装 Grunt CLI npm install -g grunt-cli

克隆 jQuery UI git repo git clone git://github.com/jquery/jquery-ui.git cd jquery-ui

安装节点模块依赖 npm install

运行 concat 任务连接文件 grunt concat

还有许多其他任务可以通过 Grunt 运行。 对于所有任务的列表: grunt --help

【问题讨论】:

    标签: jquery node.js express node-modules rickshaw


    【解决方案1】:

    在没有定义 $ 或 jquery-ui 函数的地方,在 rickshaw.js 中,我包含了相应的库

    window.$ = require('jquery');
    

    var $ = require('jquery');
    require('jquery-ui');
    

    这是一个临时解决方案,目前...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-18
      • 1970-01-01
      • 2013-12-22
      • 2015-12-09
      • 2017-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多