在我的專有應用程式上,我有一個具有以下結構的 XML 欄位
<?xml version='1.0'?>
<recipient>
<comment></comment>
<changes firstName=""/>
</recipient>
我可以使用以下腳本寫入它。
var recipient = NLWS.nmsRecipient.create(
{recipient:{
email : '[email protected]',
lastName : 'D',
firstName : 'G',
origin : 'Preference Centre'}})
recipient.changes.firstName = 'tmpName'
recipient.comment = "CommentsHere";
recipient.save();
雖然上述方法有效,但我想知道為什么我不能使用以下方式。
var recipient = NLWS.nmsRecipient.create(
{recipient:{
email : '[email protected]',
lastName : 'D',
firstName : 'G',
origin : 'Preference Centre'
changes.firstName : 'tmpFirstName'}})
recipient.comment = "CommentsHere";
recipient.save();
我嘗試了以下變體無濟于事,正確的方法是什么?
[changes/@firstName] : 'tmpFirstName'
[changes.firstName] : 'tmpFirstName'
{changes.firstName} : 'tmpFirstName'
{"changes":"firstName"} : 'tmpFirstName'

更新
為了能夠擴展我的架構/表,我對我的架構進行了以下更改
<!--tmp recipient changes 18122021 DG-->
<element label="changes" name="changes" xml="true">
<attribute label="tmp firstName" name="firstName" type="string" xml="true"/>
<attribute label="tmp LastName" name="lastName" type="string" xml="true"/>
<attribute label="tmp email" name="email" type="string" xml="true"/>
<attribute label="tmp emailPreferredName" name="emailPreferredName" type="string"
xml="true"/>
<attribute label="tmp JOB_TITLE" name="JOB_TITLE" type="string" xml="true"/>
<attribute label="tmp company" name="company" type="string" xml="true"/>
<attribute label="tmp blackListEmail" name="blackListEmail" type="string"
xml="true"/>
<attribute label="tmp lawfulBasis" name="lawfulBasis" type="string" xml="true"/>
</element>
<!--tmp recipient changes -->
因此,我可以使用 XML xpath 將資料存盤在單個 mData 欄位(資料)中
var recipient = NLWS.nmsRecipient.create(
{recipient:{
email : '[email protected]',
lastName : 'D',
firstName : 'G',
origin : 'Preference Centre'}})
recipient.changes.firstName = 'tmpName'
recipient.changes.lastName= 'tmpName'
recipient.changes.company= 'tmpCompany'
recipient.comment = "CommentsHere";
recipient.save();
uj5u.com熱心網友回復:
我認為正確的方法應該是這樣的。
var recipient = NLWS.nmsRecipient.create(
{recipient:{
email : '[email protected]',
lastName : 'D',
firstName : 'G',
origin : 'Preference Centre',
changes: {
firstName : 'tmpFirstName'
}
}})
recipient.comment = "CommentsHere";
recipient.save();
區別在于構造物件的正確方法。
您的方式應該會引發語法錯誤,因為您嘗試changes.firstName在創建物件之前訪問
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/385797.html
標籤:javascript json xml
