【问题标题】:Merge table in table Lua在 Lua 表中合并表
【发布时间】:2017-10-11 15:57:01
【问题描述】:

如何将可变长度的 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)

【问题讨论】:

    标签: soap lua


    【解决方案1】:

    每次循环都会将plutable 设置为一个新表。您可能想要插入到新的或现有的表中。

    plutable = 替换为

    plutable = plutable or {}
    table.insert(plutable, { 
        tag = "hot1:TicketDetail",
        { tag = "hot1:PLU", plunr },
        { tag = "hot1:Description", pluname }})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 2015-04-30
      • 2011-05-30
      • 2011-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多