我有一个 JSON 字符串,如下所示:
[
{"TypeName":"Double","TypeID":14},
{"TypeName":"Single","TypeID":43},
{"TypeName":"Family","TypeID":7}
]
在 KnockOut 中调用该函数后生成:
self.save = function() {
var dataToSave = $.map(self.lines(), function(line) {
return line.product() ? {
TypeName: line.category().TypeName,
TypeID: line.category().TypeID
: undefined
});
alert(JSON.stringify(dataToSave));
但是,我想在模型中再添加 3 条信息,然后再将其发布回我的服务器 - 同时发送姓名、电子邮件和电话:
{
"Name":"Mark",
"Email":"me@me.com",
"Tel":"0123456789",
"Rooms":
[
{"TypeName":"Double","TypeID":14},
{"TypeName":"Single","TypeID":43},
{"TypeName":"Family","TypeID":7}
]
}
是否有将此信息添加到 JSON 的正确方法,或者它是否简单:
var toSend = "{\"Name\":\"Mark\":\"Email\":\"me@me.com\", \"Tel\":\"0123456789\",\"Rooms\":"
+ JSON.stringify(dataToSave) + "}";
谢谢,
标记