更新javascript对象内的值
我正在使用AffirmJavaScriptAPI,我需要能够更新签出对象中的值,但在这样做时遇到了困难。我试过上面提到的东西,但不起作用 基本上,对象看起来像这样:更新javascript对象内的值,javascript,javascript-objects,Javascript,Javascript Objects,我正在使用AffirmJavaScriptAPI,我需要能够更新签出对象中的值,但在这样做时遇到了困难。我试过上面提到的东西,但不起作用 基本上,对象看起来像这样: affirm.checkout({ "merchant":{ "user_confirmation_url":"https://example.com/checkout/", "user_cancel_url":"https://example.com/exit" }, "confi
affirm.checkout({
"merchant":{
"user_confirmation_url":"https://example.com/checkout/",
"user_cancel_url":"https://example.com/exit"
},
"config":{
"financial_product_key":"XXXXXXXXX"
},
"shipping":{
"name":{
"full":"Blah Person"
},
"address":{
"line1":"123 example street",
"city":"Blah",
"state":"IL",
"zipcode":"12345",
"country":"US"
}
},
"billing":{
"name":{
"full":"Dirty Larry"
},
"address":{
"line1":"123 blah street",
"city":"foo",
"state":"IL",
"zipcode":"12345",
"country":"US"
}
},
"items":[
{
"display_name":"Example Product",
"sku":"123",
"unit_price":"1222",
"qty":"1",
"item_image_url":"https://example.com/kitty.jpg",
"item_url":"https://example.com/product/123"
}
],
"discounts":{
"discount_name":{
"discount_amount":0
}
},
"metadata":{
"shipping_type":"Ground"
},
"order_id":"XXXXXXXXXXXXXXXXXX",
"shipping_amount":0,
"tax_amount":0,
"total":67599
});
以上都是在第一次页面加载时设置的,但是客户仍然可以更新购物车中的项目,因此如果发生这些更改,我需要将它们添加到上面的对象中
我尝试了assfirm\u checkout[“shipping\u amount”]=123
,它不会更新发货总额。也不能确认checkout.shipping\u amount=123
有人能告诉我我做错了什么吗?你可以试试这个:
{
merchant: "foo bar",
config: "baz"
}
然后你可以通过
checkout.merchant = 123
您应该将签出对象定义为affirm.checkout函数上下文之外的变量。这样,您就可以直接访问对象的内容并将其传递给confirm.checkout(yourCheckoutObject)
assfirm.checkout
是否将对象添加到varassfirm\u checkout
?如果是这样的话,affirm\u checkout.shipping\u amount=123
应该可以工作。我已经尝试了两种方法,但仍然没有更新。这是文档也许你有错误的代码?结账
向我建议这是您进行付款或其他操作之前的最后一个阶段?是的,您是对的assfirm.checkout.post()
是被调用的,并将它们带到assfirm网站,似乎它有一个set
函数。尝试确认.checkout.set('shipping\u amount',newamount).OP已经尝试过了。它不仅仅是一个对象,它是一个传递给函数的对象。因此,访问它并不是那么直截了当。
var yourCheckoutObject = {}; //define default or placeholder values
yourCheckoutObject.shipping_amount = 2000; //amounts are expressed in integer USD cents
affirm.checkout(yourCheckoutObject); //pass the object to the checkout function