【问题标题】:getting date value from ION slider with moment when user changes the value当用户更改值时,从 ION 滑块获取日期值
【发布时间】:2015-04-17 03:03:39
【问题描述】:

我对我的编程问题有疑问,我正在使用 ION Slider (http://ionden.com/a/plugins/ion.rangeSlider/demo_advanced.html) 和 Moment.js 进行日期范围操作。我需要为我的程序设置特定的日期范围和特定的日期范围选择器。

每当用户更改值时,它都应该更新数据库。但我在这里有一个小问题,滑块在 console.log() 中没有显示正确的格式。请帮助我解决这种情况。我的代码是,

var startDate = moment("2014-01-05");
    var endDate = moment("2014-01-13");

    range.ionRangeSlider({
        type: "double",
        grid: true,

        min: +moment(startDate).format("X"),
        max: +moment(endDate).format("X"),

        from: +moment(endDate).subtract(5, "days").format("X"),
        to: +moment(endDate).subtract(2, "days").format("X"),

        prettify: function (num) {
            return moment(num, "X").format("dddd, MMM Do YYYY");
        }
    });

    range.on("change", function () {
    var $this = $(this),
        from = $this.data("from"),
        to = $this.data("to");

        console.log(from + " - " + to);
    });

控制台日志,

1389113336 - 1389373200
jquery-... > eval (line 28)
1389111677 - 1389373200
jquery-... > eval (line 28)
1389111345 - 1389373200
jquery-... > eval (line 28)
1389109686 - 1389373200
jquery-... > eval (line 28)
1389108359 - 1389373200
jquery-... > eval (line 28)
1389106368 - 1389373200
jquery-... > eval (line 28)
1389103713 - 1389373200
jquery-... > eval (line 28)
1389102054 - 1389373200

它应该在控制台日志中显示日期。

【问题讨论】:

    标签: javascript slider momentjs


    【解决方案1】:

    我自己找到了答案,

    var startDate = moment("2014-01-01");
        var endDate = moment("2014-01-30");
    
        range.ionRangeSlider({
            type: "double",
            grid: true,
            force_edges: true,
    
            min: +moment(startDate).format("X"),
            max: +moment(endDate).format("X"),
    
            from: +moment(endDate).subtract(5, "days").format("X"),
            to: +moment(endDate).subtract(2, "days").format("X"),
    
            prettify: function (num) {
                return moment(num, "X").format("dddd, MMM Do YYYY");
            }
        });
    
    
        range.on("change", function () {
                var $this = $(this), 
                    from = $this.data("from"),
                    to = $this.data("to");
                    console.log( moment(from,"X").format("dddd, MMM Do YYYY") + " - " + moment(to,"X").format("dddd, MMM Do YYYY"))
            });
    
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多