Change jQuery Knob Min/Max value

三世轮回 提交于 2019-12-10 20:26:15

问题


I'm working on an angular wrapper for the jquery-knob widget. The following works as long as the maximum value doesn't change. If it does, the ng-model binding is lost. If I don't destroy the knob widget at the beginning of the watch, the max value doesn't change.

//Directive
app.directive('knobWidget', function () {
    return {
        scope: {
            maxbinding: "=maxbinding",
            maxbindingprop: "@maxbindingprop"
        },
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, elem, attrs, ngModel) {
            ngModel.$render = function () {
                $(elem).val(ngModel.$viewValue).trigger("change");
            };          
            scope.$watch('maxbinding', function (newVal) {
                $(elem).knob('destroy');
                $(elem).knob({
                    min: 0,
                    max: scope.maxbinding[scope.maxbindingprop],
                    value: ngModel.$viewValue,
                    change: function (changeVal) {
                        scope.$apply(function () {
                            ngModel.$setViewValue(changeVal);
                        });
                    }
                });
            });
        }
    };
});
//Markup
<input knob-widget data-min="0" maxbinding="arr" maxbindingprop="length" ng-model="currentStop" />

Doing:

$(elem).knob('max', scope.maxbinding[scope.maxbindingprop]);

doesn't work either. Any ideas?


回答1:


Using trigger('configure') followed by trigger('change') should do the trick

$(elem).trigger('configure', {
                  'max': scope.maxbinding[scope.maxbindingprop];
              });
$(elem).trigger('change');

Source



来源:https://stackoverflow.com/questions/24419582/change-jquery-knob-min-max-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!