knockoutjs: can we create a dependentObservable function with a parameter?

前端 未结 3 904
忘掉有多难
忘掉有多难 2020-11-30 10:52

I have multiple input boxes that I want to hide/unhide based on a selection from user.

I can achieve this by having a separate dependentObservable for each input an

3条回答
  •  天涯浪人
    2020-11-30 11:27

    Taking the idea from @Arxisos even further, I came up with this.

    self.showField = function (fieldName)
    {
        return ko.dependentObservable(function () 
        {
            return this.selectedType() ? IsFeatureVisible(this, fieldName) : false;
        }, this)();
    };
    

提交回复
热议问题