簡體   English   中英

Knockout.js - 如果條件為真,則更改返回復選框值 null

[英]Knockout js - Change return checkbox value null if condition true

我是 Knockout.js 的新手,我有復選框和帶條件的返回值。

如果條件為真,我想更改返回值 null,但我不知道如何:

isChecked: ko.computed(function () {
            return quote.paymentMethod() ? quote.paymentMethod().method : 'payu';
        }),

        isCheckedToShowTooltip: function () {
            $(".loading-mask").addClass("hide");

            if($(".payment-method").length == 0) {
                if ($(".multiple_payment_method").length == 0) {
                    $(".billing-address-list").before('<h4 class="multiple_payment_method"><span>Datos de envío</span></h4>');
                    $(".block.items-in-cart.active div.title").addClass("hide");
                    $(".block.items-in-cart").before('<h4 class="multiple_payment_method"><span>Resumen de tu compra</span></h4>');
                    $("#checkout-payment-method-load").before('<h4 class="multiple_payment_method"><span>Método de pago</span></h4>');
                }
                if ($(".multiple_payment_method").length == 3) {
                    this.isChecked() = null; //<----------------Here not work
                }
            }

            if(quote.paymentMethod()) {
                if($("#seccion-payu-below").length > 0) {
                    $("#seccion-payu-below").remove();
                }

                if($("#seccion-efecty-below").length > 0) {
                    $("#seccion-efecty-below").remove();
                }

                switch(quote.paymentMethod().method) {
                  case "payu":
                          $('#initial-payu-container').remove();
                          $('#checkout-payment-method-load').removeClass('container-initial');
                          $("#payment-methods-group-list" ).after("<div id='seccion-payu-below'>" + $("#seccion-payu").html() + "</div>");
                          $("#seccion-payu-below button").removeAttr("data-bind data-posicion data-origen");

                          if($("#seccion-payu button").hasClass("disabled")) {
                              $("#seccion-payu-below button").attr('disabled','disabled').addClass("disabled");
                          } else {
                              $("#seccion-payu-below button").removeAttr('disabled','disabled').removeClass("disabled");
                          }

                          $("#seccion-payu-below button").attr({ id: "button_payu_below", type: "button", onclick: "submitPaymentMethod('" + quote.paymentMethod().method + "');" });

                          if($('#payu').is(':checked')) {
                              $('#seccion-payu-below').show();
                          }
                    break;
                  case "efecty":
                          $('#initial-payu-container').remove();
                          $('#checkout-payment-method-load').removeClass('.container-initial');
                          $("#payment-methods-group-list" ).after("<div id='seccion-efecty-below'>" + $("#seccion-efecty").html() + "</div>");
                          $("#seccion-efecty-below button").removeAttr("data-bind data-posicion data-origen");

                          if($("#seccion-efecty button").hasClass("disabled")) {
                              $("#seccion-efecty-below button").attr('disabled','disabled').addClass("disabled");
                          } else {
                              $("#seccion-efecty-below button").removeAttr('disabled','disabled').removeClass("disabled");
                          }

                          $("#seccion-efecty-below button").attr({ id: "button_efecty_below", type: "button", onclick: "submitPaymentMethod('" + quote.paymentMethod().method + "');" });

                          if($('#efecty').is(':checked')) {
                              $('#seccion-efecty-below').show();
                          }
                    break;
                }
            }
        },

我試過提到的條件但沒有工作

我知道讀寫屬性,但我不知道這是否是我的情況

有任何想法嗎? 謝謝!

感謝 epascarello 我編輯了條件,並解決了問題,為此添加了新的驗證:

isChecked: ko.computed(function () {
            if (quote.paymentMethod()) {
                return quote.paymentMethod().method
            } else if (!rendererList._latestValue.some(item => item.type === 'efecty')) {
                return 'payu';
            } else {
                $('#checkout-payment-method-load').removeClass('container-initial');
                return null;
            }
        }),

問候!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM