本文介绍了如何使计算的可观察可写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!





我有scnerio我想让一个字段计算observable如果没有点击复选框那么用户写入应该存储到哪个那个领域



地址1: -

地址2: -



复选框: - 与上面相同



邮寄地址: -



现在这里我想要的如果选中复选框,那么用户所拥有的内容应与上述值相同。如果没有,那么用户可以输入不同的邮寄地址



我尝试过:



//clientViewModel.client_mailingAddress = ko.computed(function(){

// if(clientViewModel.client_isMailingAddressReadOnly()){

//返回clientViewModel.client_AddressLine1 ()+''+ clientViewModel.client_AddressLine2()+''+ clientViewModel.client_AddressLine3()

//}

//});



这里复选框工作perfctl但现在当复选框没有检查,如果我为我的maling地址输入一些东西,将其视为未定义..

Hi ,

I have scnerio where i want to make one field computed observable if check box is clicked if not then whatver user writes into it that should store into that field

Address 1 :-
Address 2 :-

Check box :- is same as above

Mailing address :-

now here what i want to do is if check box is checked then whatver user has entred should be same as above value. If not then user can enter differnt mailing address

What I have tried:

//clientViewModel.client_mailingAddress = ko.computed(function () {
// if (clientViewModel.client_isMailingAddressReadOnly()) {
// return clientViewModel.client_AddressLine1() + ' ' + clientViewModel.client_AddressLine2() + ' ' + clientViewModel.client_AddressLine3()
// }
//});

here check box works perfctl but now when check box not checked and if i enter something for my maling address that takes it as undefined..

推荐答案

chemistViewModel.chemist_mailingAddress = ko.pureComputed({
        read: function () {
            if (chemistViewModel.chemist_isMailingAddressReadOnly()) {
                var updatedAddress = chemistViewModel.chemist_AddressLine1() + ' ' + chemistViewModel.chemist_AddressLine2() + ' ' + chemistViewModel.chemist_AddressLine3();
                return updatedAddress;
            }
            else {
                var updatedAddress = chemistViewModel.chemist_mailingAddressWritable();
                return updatedAddress;
            }
        },
        write: function (value) {
            if (!chemistViewModel.chemist_isMailingAddressReadOnly()) {
                chemistViewModel.chemist_mailingAddressWritable(value);
            }
        },
        owner: this
    });


这篇关于如何使计算的可观察可写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 07:00