Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么datepicker值没有更改?_Javascript_Angularjs - Fatal编程技术网

Javascript 为什么datepicker值没有更改?

Javascript 为什么datepicker值没有更改?,javascript,angularjs,Javascript,Angularjs,我在一张表格里有两个日期选择器。当用户选择第一个日期时,应更新第二个日期选择器的最小和最大日期(自选择日期起一年)。但在我的例子中,当我第一次在第一个日期选择器中选择日期时,最小和最大日期只更新一次。但是,如果我更改选择,则第二个日期选择器不会使用更改的值进行修改 html: 每次我都可以看到stDate和enDate值更改,但第二个日期选择器的开始日期和结束日期没有更新。我被困了两天。请帮助将值传递到指令时,将创建一个隔离作用域。您可以使用指令的scope属性定义如何处理传递到此指令中的值 .

我在一张表格里有两个日期选择器。当用户选择第一个日期时,应更新第二个日期选择器的最小和最大日期(自选择日期起一年)。但在我的例子中,当我第一次在第一个日期选择器中选择日期时,最小和最大日期只更新一次。但是,如果我更改选择,则第二个日期选择器不会使用更改的值进行修改

html:


每次我都可以看到
stDate
enDate
值更改,但第二个日期选择器的开始日期和结束日期没有更新。我被困了两天。请帮助

将值传递到指令时,将创建一个隔离作用域。您可以使用指令的scope属性定义如何处理传递到此指令中的值

.directive('datePicker2', function () {

    return {
        scope: {
            name: "=",
        },
        link: linker
    }

    function linker (scope, element, attrs) {
        scope.$watch('productionDate', function (newVal, oldVal) {
            console.log('productionDate===='+scope.productionDate);
            splittedDateString = scope.productionDate.split('/');
            stDate = new Date(splittedDateString[0], splittedDateString[1]-1, splittedDateString[2]);
            enDate = new Date(stDate.getFullYear()+1, splittedDateString[1]-1, splittedDateString[2]);
            element.datepicker({
                format: "yyyy/mm/dd",
                todayHighlight: true,
                startDate: stDate || new Date(),
                endDate:enDate || new Date(),
                autoclose: true
            });
            if(newVal){
                scope['nextReviewDate'] = newVal;
            }
            else{
                scope['nextReviewDate'] = setDate();
            }
        });
    };
}

将值传递到指令时,将创建一个隔离作用域。您可以使用指令的scope属性定义如何处理传递到此指令中的值

.directive('datePicker2', function () {

    return {
        scope: {
            name: "=",
        },
        link: linker
    }

    function linker (scope, element, attrs) {
        scope.$watch('productionDate', function (newVal, oldVal) {
            console.log('productionDate===='+scope.productionDate);
            splittedDateString = scope.productionDate.split('/');
            stDate = new Date(splittedDateString[0], splittedDateString[1]-1, splittedDateString[2]);
            enDate = new Date(stDate.getFullYear()+1, splittedDateString[1]-1, splittedDateString[2]);
            element.datepicker({
                format: "yyyy/mm/dd",
                todayHighlight: true,
                startDate: stDate || new Date(),
                endDate:enDate || new Date(),
                autoclose: true
            });
            if(newVal){
                scope['nextReviewDate'] = newVal;
            }
            else{
                scope['nextReviewDate'] = setDate();
            }
        });
    };
}

在对第一个字段进行任何更改后,我可以使用点运算符访问第二个
指令中的值。但只有更改没有反映在datepicker中。问题现在解决了。实际上,我用于此目的的引导日期选择器并不刷新。请在这里找到答案。在对第一个字段进行任何更改后,我可以使用点运算符访问第二个
指令中的值。但只有更改没有反映在datepicker中。问题现在解决了。实际上,我用于此目的的引导日期选择器并不刷新。请在这里找到答案仍然无法解决问题。有人能帮忙吗?还是解决不了问题。有人能帮忙吗?
.directive('datePicker2', function () {

    return {
        scope: {
            name: "=",
        },
        link: linker
    }

    function linker (scope, element, attrs) {
        scope.$watch('productionDate', function (newVal, oldVal) {
            console.log('productionDate===='+scope.productionDate);
            splittedDateString = scope.productionDate.split('/');
            stDate = new Date(splittedDateString[0], splittedDateString[1]-1, splittedDateString[2]);
            enDate = new Date(stDate.getFullYear()+1, splittedDateString[1]-1, splittedDateString[2]);
            element.datepicker({
                format: "yyyy/mm/dd",
                todayHighlight: true,
                startDate: stDate || new Date(),
                endDate:enDate || new Date(),
                autoclose: true
            });
            if(newVal){
                scope['nextReviewDate'] = newVal;
            }
            else{
                scope['nextReviewDate'] = setDate();
            }
        });
    };
}