knockout computed 실례

4693 단어 knockout
function Privilege(options) {

    var self = this;

    self.fieldId = options.fieldId;

    self.readAccessType = ko.observable(options.readAccess);

    self.writeAccessType = ko.observable(options.writeAccess);

    self.readAccess = ko.computed({

        read: function () {

            return this.readAccessType() == 1;

        },

        write: function (value) {

            if (value == true) {

                this.readAccessType(1);

            } else {

                this.readAccessType(2);

            }

        },

        owner: this

    });

    self.readDeny = ko.computed({

        read: function () {

            return this.readAccessType() == 0;

        },

        write: function (value) {

            if (value == true) {

                this.readAccessType(0);

            } else {

                this.readAccessType(2);

            }

        },

        owner: this

    });



    self.writeAccess = ko.computed({

        read: function () {

            return this.writeAccessType() == 1;

        },

        write: function (value) {

            if (value == true) {

                this.writeAccessType(1);

            } else {

                this.writeAccessType(2);

            }

        },

        owner: this

    });

    self.writeDeny = ko.computed({

        read: function () {

            return this.writeAccessType() == 0;

        },

        write: function (value) {

            if (value == true) {

                this.writeAccessType(0);

            } else {

                this.writeAccessType(2);

            }

        },

        owner: this

    });

    return self;

}

좋은 웹페이지 즐겨찾기