2017-10-11 247 views
-2

如何合併LUA表與變量長度到其他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) 

回答

1

每次通過循環設置plutable到一個新表。您可能想要插入新的或現有的表格。

更換plutable =

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

謝謝你的信息,它的作品! –