以编程方式触发Kendo Chart.seriesClick事件

时间:2014-05-01 14:46:01

标签: javascript jquery angularjs kendo-ui angular-kendo

这是一个非常小而简单的问题。在线查看我无法找到任何东西,但我希望能够对我们的剑道图进行单元测试,特别是seriesClick事件按预期工作。问题是我似乎找不到触发事件的方法。我试图通过jQuery定位图表系列并调用.click()。尝试这种方法没有给我什么,所以在一个废除的时刻我试着点击一切

$('*').each(function(){
    $(this).click();
});

没有这样的运气。这是chartOptions代码段

$scope.chartOptions = {
                //...
                // On Click add the criteria to the serach bar.
                seriesClick: function (series) {
                        console.log("seriesClick");
                        //Do stuff here                            
                        $scope.$apply();
                    }
                }
            };

当我在单元测试中尝试运行上面提到的jQuery代码时,我没有得到控制台输出。在这里。

xit('should update the searchbar when a series item has been clicked', inject(function ($compile, $rootScope, $timeout) {
        var scope = $rootScope.$new();
        //Write out the directive
        //We have a directive that will replace this tag with the kendo-chart directive
        var ele = $compile('<chart></chart>')(scope); 
        angular.element(document.body).append(ele);
        scope.$digest();
        $timeout.flush(0);
        scope = ele.isolateScope();

        console.log('clicking everything');
        $('*').each(function () {
            $(this).click();
        });

我已经向telerik论坛提交了同样的问题,希望得到“专家”的一些建议,但我得到的反应几乎和SO一样快。

修改 我确实遇到了Telerik论坛中的这个post,我希望我需要做的不是“目前不支持开箱即用”。

1 个答案:

答案 0 :(得分:1)

在询问telerik forums之后,我终于找到了这个答案

 element.mousedown().mouseup()    //Trigger events for Chrome, Firefox and IE9
            .trigger(jQuery.Event("MSPointerDown", { originalEvent: {} })).trigger(jQuery.Event("MSPointerUp", { originalEvent: {} }))  //Trigger event for IE10
            .trigger(jQuery.Event("pointerdown", { originalEvent: {} })).trigger(jQuery.Event("pointerup", { originalEvent: {} })); //Trigger event for IE11

显然它会侦听mousedown()mouseup()事件。然后看到它没有&#39;为IE10和11工作我需要使用另一种方式触发mousedown()/ mouseup()