【问题标题】:My jQuery doesn't seem to be working with Wijmo Grid我的 jQuery 似乎不适用于 Wijmo Grid
【发布时间】:2013-02-15 04:55:53
【问题描述】:

我构建了一个充满单元格的智能数据网格,可以识别(模糊)它们是否被更改,以及值是上升还是下降。

这就是它的样子。当用户悬停已更改的框并告诉他们页面首次加载时的值是什么时,会出现灰色工具提示。



我想将其转换为 Wijmo Grid,但保留相同的上/下脚本以显示值何时以及如何更改。但是,当我将表格初始化为 Wijmo 网格时,我的脚本突然停止工作在所有浏览器中。

问题:为什么会发生这种情况,是否有简单的解决方法?不能用传统的 jQuery 和 Javascript 访问 Wijmo 单元格吗?

部分 HTML 代码 (Full code and working example without Widjmo here):

<table id="data-grid">
    <thead>
        <tr>
            <th>March</th>
            <th>April</th>
            <th>May</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><input type="text" value="12000" /></td>
            <td><input type="text" value="1000" /></td>
            <td><input type="text" value="100000" /></td>
        </tr>

这是我当前的 jQuery 代码 (Full code and working example without Widjmo here):

$(function() {
    // Initializes data grid as a Widjmo Grid (currently commented out)
    //$("#data-grid").wijgrid();

    // Array to store the initial values in grid
    var initialValues = [];

    // Assigns an index ID to each cell in the grid
    $('input').each(function(index) {
        initialValues[index] = $(this).val();
        $(this).data('id', index);
    });

    // Checks cell(s) for changes on blur (lose focus)
    $("input").blur(function() {
        var $t = parseInt($(this).val(), 10);
        var $s = parseInt(initialValues[$(this).data('id')], 10);

        // Value has changed
        if($t != $s) {
            var sign = "";
            if($t-$s > 0) {
                sign="+";
            }
            $(this).parent().children(".tooltip").remove();
            $(this).parent().append("<div class='tooltip'>Initial " + $s + "<br/>Change " + sign + ($t-$s) + "</div>");
        }

        // Value is no different from intial value
        if($t == $s) {
            $(this).removeClass("up down");
            $(this).parent().children(".tooltip").remove();
            $(this).parent().children(".up-indicator, .down-indicator").remove();
        }

        // Value is greater than initial
        else if($t > $s) {
            $(this).removeClass("up down");
            $(this).parent().children(".up-indicator, .down-indicator").remove();
            $(this).addClass("up");
            $(this).parent().append("<div class='up-indicator'></div>");
        }

        // Value is less than initial
        else if($t < $s) {
            $(this).removeClass("up down");
            $(this).parent().children(".up-indicator, .down-indicator").remove();
            $(this).addClass("down");
            $(this).parent().append("<div class='down-indicator'></div>");
        }

        // Conpute the net change
        netChange(initialValues);
    });

    // Displays tooltip of changed items
    $("input").hover(function() {
        $(this).parent().children(".tooltip").toggle();
    });

    // Computes the net change in the data grid
    function netChange(initialValues) {
        var runningTotal = 0;
        $('input').each(function() {
           runningTotal += parseInt($(this).val(), 10);
        });

        var intialTotal = 0;
        for (var i = 0; i < initialValues.length; i++) {
            intialTotal += parseInt(initialValues[i], 10);
        }

        var changes = $(".up, .down").length;

        $("#items").text(changes + " Items");
        $("#net").text("Net: " + (runningTotal - intialTotal));
    }
});

【问题讨论】:

  • 你用的是什么浏览器?
  • Chrome 版本 25.0 [.1364.152]

标签: jquery wijmo


【解决方案1】:

Wijmo 插件代码在其代码中使用$.browser.msie,该代码在 jQuery 1.3 中不推荐使用,并在 jQuery 1.9 中完全删除。请参阅 jQuery 文档:http://api.jquery.com/jQuery.browser/ 和下面是 bold 中关于它被删除的原因的评论。

我们建议不要使用此属性;请尝试改用特征检测(参见 jQuery.support)。 jQuery.browser 可能会在 jQuery 的未来版本中移动到插件中。


在我在小提琴中选择早期版本的jQuery 1.8 后,您的工具提示代码工作一次。

固定小提琴: http://jsfiddle.net/Fgdec/13/


在您的小提琴中,您选择了没有$.browser.msie 的 jQuery 1.9,所以它在 chrome 控制台中抛出了以下错误。

Uncaught TypeError: Cannot read property 'msie' of undefined jquery.wijmo-open.all.2.3.8.min.js:31
(anonymous function) jquery.wijmo-open.all.2.3.8.min.js:31
(anonymous function) jquery.wijmo-open.all.2.3.8.min.js:61
Uncaught TypeError: Cannot read property 'msie' of undefined jquery.wijmo-complete.all.2.3.8.min.js:34
(anonymous function) jquery.wijmo-complete.all.2.3.8.min.js:34
(anonymous function) jquery.wijmo-complete.all.2.3.8.min.js:34

【讨论】:

  • 我发布的代码正在运行——我已经注释掉了 Wijmo 初始化。如果取消注释 jQuery 中的第 3 行以初始化 Wijmo 网格,您会看到 jQuery 变得无响应。这就是我遇到的问题。
  • 我收回了。显然 jQuery 1.9.x 毕竟是问题所在。谢谢你的收获!
猜你喜欢
  • 2013-04-23
  • 2014-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多