Angular ui-timepicker - 不改变ng-model中的数据

时间:2016-11-01 13:36:57

标签: javascript angularjs json angular-ui timepicker

在html中:

<input ng-model="schedule.when" ui-timepicker="timePickerOptions"/>

在js中 - 我有这个:

let toTime = (dStr) => {
    var now = new Date();
    now.setHours(dStr.substr(0, dStr.indexOf(":")));
    now.setMinutes(dStr.substr(dStr.indexOf(":") + 1));
    now.setSeconds(0);
    return now;
}

data.MowingDays[i].when = moment(toTime(data.MowingDays[i].when)); //(13:00);

首先,我将字符串从json转换为moment对象。   - momentjs

这是我提出的选项:

$scope.timePickerOptions = {
        step: 20,
        appendTo: 'body',
        timeFormat: 'H:ss' ,
        change: function(data)
        {
                $scope.selectChanged();
                console.log(date); // Sun Dec 31 1899 15:00:00 GMT+0200 (Jerusalem Standard Time)
                $scope.$apply();

        }
    };

当我点击&#34;保存&#34; ,它需要保存新数据。 - 更新json

问题在于&#34; data.MowingDays [i] .when&#34;在JSON,而不是改变。

总而言之: &#34; 2016-11-01T11:00:00.070Z&#34;

json是:

        let scheduleXJSON =
        {
            "MowingDays":
            [{
                "day" : "sun",
                "active": false,
                "when": "13:00",
                "where": "Base(main)",
                "howlong": "Max (Up to 90 Min)"
            },
            {
                "day"   : "mon",
                "active": false,
                "when": "13:00",
                "where": "Base(main)",
                "howlong": "Max (Up to 90 Min)"
            }]
        }

0 个答案:

没有答案