高库存inputDateParser触发三遍 [英] Highstock inputDateParser fires three times

查看:88
本文介绍了高库存inputDateParser触发三遍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定是什么原因导致它通过日期日历.这是为rangeSelector

I am not sure what cause it to fire three times after selecting a date through date calendar. Here is the options set for rangeSelector

rangeSelector:{
    enabled:true,
    inputEnabled: true,
    inputDateFormat: '%d/%m/%Y',
    inputEditDateFormat: '%d/%m/%Y',                    
    inputDateParser: function (value) {
        value = value.split('/');
        console.log(value);
        return Date.UTC(
          parseInt(value[0]),
          parseInt(value[1]) - 1,
          parseInt(value[2])
        );
    }
}

通过使用backbone.view jquery选择器,这是我如何初始化图表

by using backbone.view jquery selector, here how i initiate the chart

this.$el.highcharts(Options, this.extra);

extra作为触发日期选择器的其他设置

and extra as additional settings to trigger the date picker

highlightSer: function (chart){         
      setTimeout(function () {              
         $('input.highcharts-range-selector', $(chart.container).parent())
            .datepicker({
                format: "dd/mm/yyyy",    
                todayBtn: "linked",
                autoclose: true,
                todayHighlight: true,
                orientation: "auto right"
            });             
      }, 0);            
}

有人经历过吗?

推荐答案

@see

@seeARMS solution from this SO worked for me, with one modification:

为您的活动创建单独的功能

一个函数具有datePicker方法和您的设置:

One function has the datePicker method and your settings:

$('input_with_date_picker').datePicker({...});

一个单独的函数控制您的on changeDate事件:

A separate function controls your on changeDate event:

$(document).on('changeDate', 'input_with_date_picker', function({..do something..}));

或:

$('input_with_date_picker').on('changeDate', function({..do something..}));

更新:

您在注释中提供的小提琴可以按预期工作,因为您添加了功能:

Update:

The fiddle you provided in the comments is working as expected because of your added function:

$('input.highcharts-range-selector').on('changeDate', function(e) {
    alert(e.date);                                     
});

在页面加载时,它执行两次,因为您有两个匹配的元素.它们似乎都是由此JS生成的:

On page load, it executes twice because you have two elements that match. They seem to both be generated by this JS:

rangeSelector:{
        enabled:true,
        inputEnabled:true,
        inputDateFormat:"%d/%m",
        inputEditDateFormat:"%d/%m/%Y",
        inputDateParser: function (value) {
            value = value.split('/');
            console.log(value);
            return Date.UTC(
                parseInt(value[0]),
                parseInt(value[1]) - 1,
                parseInt(value[2])
            );
        }       
    },

如果您更改任何一个元素的日期,该函数将执行一次,这是发布的目标.

If you change the date on either of the elements, the function executes once, which is the goal of your post.

您可能表示它不起作用,因为当您从datePicker中选择一个新日期时,日期没有更新.我不确定为什么会这样,我对海图不熟悉.

You may be indicating it's not working because the dates aren't updating when you select a new date from the datePicker. I'm not sure why this is, I'm not familiar with highcharts.

这篇关于高库存inputDateParser触发三遍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆