You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

jQuery中如何正确提取custCNFormData内的cdReference值?

Solution: Accessing cdReference from JSON String

Hey there! The problem you're facing is super common—your creditNoteHeader variable is holding a JSON string, not a JavaScript object. Even though the console output looks like an object, it's actually just text formatted like JSON. That's why trying to access .cdReference directly returns undefined—strings don't have properties like that!

How to Fix It

You need to convert the JSON string into a proper JavaScript object using JSON.parse(). Here's your updated code:

var custCNFormData = custCNFormSubmit(); 
var creditNoteHeader = custCNFormData.get('creditNoteHeader');

// Convert the JSON string to a JS object
var creditNoteHeaderObj = JSON.parse(creditNoteHeader);

console.log('value:'+creditNoteHeader); 
console.log('cdReference is : '+creditNoteHeaderObj.cdReference); // Now this will output "3"!

Quick Check to Confirm

If you want to verify the type of creditNoteHeader before parsing, you can add this line:

console.log(typeof creditNoteHeader); // This will log "string" if it's a JSON string

Once you parse it into an object, you'll also be able to access nested properties like creditNoteHeaderObj.customer.customerId without issues.

内容的提问来源于stack exchange,提问作者Jacel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:27:14