我正在创建一些速记 js 变量,这些变量最终将合并到父级中以创建一些 XML。我的速记js在这里做错了什么?我有点失落。
我想出了这个简短的例子来概述我的问题:
function testing() {
var attachments = [];
var attachment1 = [ "attachment" ,
[ "name", "myname1" ],
[ "type", "mytype1" ]
];
attachments.push(attachment1);
var attachment2 = [ "attachment" ,
[ "name", "myname2" ],
[ "type", "mytype2" ]
];
attachments.push(attachment2);
var email = [ "email",
[ "subject", "mySubject"],
[ "body", "myBody"],
[ "attachments", attachments ]
];
Logger.log(Xml.parseJS(email).toXmlString());
}
日志输出:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<email>
<subject>mySubject</subject>
<body>myBody</body>
<attachments>[Ljava.lang.Object;@b06f679</attachments>
</email>
理想情况下,它应该是:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<email>
<subject>mySubject</subject>
<body>myBody</body>
<attachments>
<attachment>
<name>myname1</name>
<type>mytype1</type>
</attachment>
<attachment>
<name>myname2</name>
<type>mytype2</type>
</attachment>
</attachments>
</email>