如何将LUA表与变量长度合并到另一个LUA表中。
在FOR-LOOP中我想搜索记录(plunr和pluname)并放在表格中。 如果每个记录都放在表中,我将把这个表合并到另一个"请求表"
问题是只有最后一条记录被发送到网络服务器。
for rrplu in receipt:getPLUs() do
local plunr = rrplu:getPLUNo();
local pluname = rrplu:getName();
plutable = { tag = "hot1:TicketDetail",
{ tag = "hot1:PLU", plunr},
{ tag = "hot1:Description", pluname},
}
end;
local soap_client = vpos.communication.SOAPClient (http)
local request = {
url = urlHTTPS,
soapaction = "http://blablabla.com/IXmlPosService/Charge",
namespace = {hot="http://blablabla.com/",
hot1="http://schemas.datacontract.org/2004/07/BlaBla.Web.DataContracts"},
method = "hot:Charge",
body = { tag = "hot:Charge",
{ tag = "hot:authentication",
{ tag = "hot1:Token", TokenValue},
},
{ tag = "hot:request",
{ tag = "hot1:PosDate", datum},
{ tag = "hot1:TicketDetails",
plutable
},
},
}
}
result, err, err_string = soap_client:call (request)
答案 0 :(得分:1)
每次循环都会将plutable
设置为新表。您可能希望插入新表或现有表。
将plutable =
替换为
plutable = plutable or {}
table.insert(plutable, {
tag = "hot1:TicketDetail",
{ tag = "hot1:PLU", plunr },
{ tag = "hot1:Description", pluname }})