我正在制作淘汰码,以下是条件:
以下是JSP代码:
<!-- ko foreach: checkout.cart.order.productsShippingMethods() -->
<div class="row">
<input type="radio" name="shipmethod" data-bind="value: $data.methodId, checked: $parent.checkout.shippingMethod,click: $parent.checkout.setSecondaryShippingMethod($data.methodId)" value="StandardResidential">
<strong data-bind="text: $data.displayName"> </strong>
</div>
<!-- ko foreach: $data.secondaryShippingMethods -->
<div class="secDiv">
<!-- ko if: ($parentContext.$parent.checkout.cart.order.isLiftGateDeliveryMandatory() !== true && $parent.methodId === 'StandardResidential' && ($parentContext.$parent.checkout.cart.order.isLiftGateDeliveryRecommended() !== true))-->
<div class="row">
<label class="checkbox mt0">
<input type="checkbox" data-bind="value: $data.methodId, checked: $parentContext.$parent.checkout.secShippingMethods()[0]">
<strong data-bind="text: $data.displayName"> </strong>
</label>
</div>
<!-- /ko -->
</div>
<!-- /ko -->
以下是与之关联的JS:
self.setSecondaryShippingMethod = function(shipMethod){
if(shipMethod === "Ground"){
if(self.secShippingMethods !== "GoundSecondary"){
self.secShippingMethods([]);
}
if(self.cart.order.isLiftGateDeliveryMandatory() == true || self.cart.order.isLiftGateDeliveryRecommended() == true){
self.secShippingMethods([]);
self.secShippingMethods.push("GroundSecondary");
}
}
if((shipMethod === "Premium") || (shipMethod === "Platinum")){
self.secShippingMethods([]);
self.secShippingMethods.push("RemoteLocation");
}
};
现在的问题是,每当我点击任何主要方法时,所有辅助方法都会被触发到checked
data-bind
,而checked
对所有辅助方法复选框都成为真。我不确定为什么会这样。
答案 0 :(得分:0)
我的解决方案更简单,使用attr
var dta=$('input this or whatever').attr('data-bind') // all data given
alert(dta); //"value: $data.methodId, checked: $parent.checkout.shi
或if(check attr('checked')== true){}喜欢这个