0

我尝试了几种不同的方法或包装一个简单的 jquery-ui 滑块,其中第一个是:

//Slider control
TDApp.directive("tdControlSlider", ["TDSV", function (TDSV) {
     return {
           scope: {
                property: "=",
                min: "=",
                max: "=",
                step: "="
           },
           restrict: "E",
           replace: true,
           templateUrl: TDSV.TEMPLATE_PATH + "Controls/Slider.htm",
           link: function (scope, elem, attrs) {
                scope.sliderElem = elem.find(".sliderDiv").first();
                scope.sliderElem.slider({
                     min: scope.min,
                     max: scope.max,
                     step: scope.step,
                     slide: function (event, obj) {
                           scope.property = obj.value;
                           scope.$apply()
                           console.log(obj.value);
                           console.log(scope.property);                         
                     }
                });
           }
     };
}]);

我认为这不起作用,因为阴影,所以我选择传递对对象的引用及其属性之一的字符串值:

//Slider control
TDApp.directive("tdControlSlider", ["TDSV", function (TDSV) {
     return {
           scope: {
                object: "=",
                property: "@",
                min: "=",
                max: "=",
                step: "="
           },
           restrict: "E",
           replace: true,
           templateUrl: TDSV.TEMPLATE_PATH + "Controls/Slider.htm",
           link: function (scope, elem, attrs) {
                scope.sliderElem = elem.find(".sliderDiv").first();
                scope.sliderElem.slider({
                     min: scope.min,
                     max: scope.max,
                     step: scope.step,
                     slide: function (event, obj) {
                           scope.object[scope.property] = obj.value;
                           scope.$apply()
                           console.log(obj.value);
                           console.log(scope.object[scope.property]);
                     }
                });
           }
     };
}]);

在这两种情况下,控制台都会显示预期值,但模型不会更新。通常这意味着值在范围内被遮蔽,这就是我将其更改为第二个版本的原因,但这也不起作用。有任何想法吗?

4

0 回答 0