{"id":2537,"date":"2024-04-11T13:02:28","date_gmt":"2024-04-11T05:02:28","guid":{"rendered":"http:\/\/www.plm.cn\/?p=2537"},"modified":"2024-04-11T13:03:03","modified_gmt":"2024-04-11T05:03:03","slug":"lua-%e5%af%b9%e5%9b%9e%e8%bd%a6%ef%bc%88%ef%bc%89%e5%a4%84%e7%90%86%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.plm.cn\/2537\/","title":{"rendered":"lua \u5bf9\u56de\u8f66\uff08%3Cbr%3E\uff09\u5904\u7406\u65b9\u6cd5"},"content":{"rendered":"
\u6211\u4eec\u5728Gird\u5217\u51fa\u6570\u636e\u7684\u65f6\u5019\uff0c\u82e5\u6570\u636e\u5185\u5e26%3Cbr%3E\uff0c\u5176\u5b9e\u662f\u56de\u8f66\u7684\u610f\u601d\uff0c\u82e5grid\u8bfb\u51fa\u6570\u636e\u4e0d\u505a\u4efb\u4f55\u5904\u7406\uff0c\u90a3\u4e48\u5c31\u4f1a\u5f71\u54cd\u7cfb\u7edf\u8868\u8fbe<\/p>\n
<\/p>\n
\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u7f16\u8f91\u4e00\u4e2alua\u811a\u672c\uff0c\u5c06\u8fd9\u4e2a\u6570\u636e\u505a\u5904\u7406\u540e\u518d\u663e\u793a\uff08\u5728\u663e\u793a\u524d\u4e8b\u4ef6\u91cc\u9762\u5b9a\u4e49\u8fd9\u4e2alua\u811a\u672c\uff09<\/p>\n
\n–[[<\/div>\n\u00a0 \u00a0 \u529f\u80fd\u8bf4\u660e:<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 1\uff09 \u663e\u793a\u524d\u505a\u4e00\u4e9b\u5b57\u6bb5\u7684\u5904\u7406<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 2\uff09\u524d\u7aef\u5bfc\u5165\uff0c\u65b0\u589e\u6709\u6362\u884c\u7b26\u53f7\u3000%%3Cbr%%3E\u3000\u3000\uff0c\u66ff\u6362\u6210 <br> \u524d\u7aefhtml\u652f\u6301\u7684\u6362\u884c\u5185\u5bb9<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 3\uff09\u5185\u5bb9\u4e2d\u6709&\uff0c\u66ff\u6362\u6210 \uff06 \u524d\u7aef\u89e3\u6790 &\u4e0d\u652f\u6301\uff0c\u6700\u597d\u5728\u8f93\u5165\u65f6\u8fdb\u884c\u66ff\u6362<\/div>\n–]]<\/div>\njson = require(“json”)<\/div>\nmobox = require(“OILua_JavelinExt”)<\/div>\nrequire(“oi_basestrfunc”)<\/div>\n<\/div>\nfunction BeforeGridShow(strLuaDEID)<\/div>\n\u00a0 \u00a0 local nRet, strRetInfo<\/div>\n<\/div>\n\u00a0 \u00a0 local arobjs, attrs, success<\/div>\n<\/div>\n\u00a0 \u00a0 — \u83b7\u53d6\u8f93\u5165\u7684DataJson\u6570\u636e\u5305<\/div>\n\u00a0 \u00a0 nRet, strRetInfo = mobox.getCurEditDataPacket(strLuaDEID)<\/div>\n\u00a0 \u00a0 if (nRet ~= 0) then<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 mobox.error(strLuaDEID, “\u65e0\u6cd5\u83b7\u53d6\u6570\u636e\u5305!”)<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 return<\/div>\n\u00a0 \u00a0 end<\/div>\n\u00a0 \u00a0 if (strRetInfo == ” or strRetInfo == nil) then<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 return<\/div>\n\u00a0 \u00a0 end<\/div>\n<\/div>\n\u00a0 \u00a0 — \u89e3\u6790\u6570\u636e\u5305\uff0c\u6570\u636e\u5305\u683c\u5f0f<\/div>\n\u00a0 \u00a0 — [{“id”:””,”attrs”:[{“attr”:””,”value”:””},..]},..]<\/div>\n<\/div>\n\u00a0 \u00a0 local n, nCount<\/div>\n<\/div>\n\u00a0 \u00a0 success, arobjs = pcall(json.decode, strRetInfo)<\/div>\n\u00a0 \u00a0 if (success == false) then<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 mobox.error(strLuaDEID, “\u975e\u6cd5\u7684JSON\u683c\u5f0f!”)<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 return<\/div>\n\u00a0 \u00a0 end<\/div>\n<\/div>\n\u00a0 \u00a0 nCount = #arobjs<\/div>\n\u00a0 \u00a0 if (nCount == 0) then<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 return<\/div>\n\u00a0 \u00a0 end<\/div>\n<\/div>\n\u00a0 \u00a0 local obj, attrs<\/div>\n\u00a0 \u00a0 local nattr_count<\/div>\n\u00a0 \u00a0 local strRow, strAttr, strItem<\/div>\n\u00a0 \u00a0 local strDataJson<\/div>\n\u00a0 \u00a0 local id, strValue<\/div>\n\u00a0 \u00a0 local strAttrs<\/div>\n\u00a0 \u00a0 strDataJson = ‘[‘<\/div>\n\u00a0 \u00a0 local seg = {}<\/div>\n\u00a0 \u00a0 local nSegCount = 0<\/div>\n\u00a0 \u00a0 for n = 1, nCount do<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 obj = arobjs[n]<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 attrs = obj.attrs<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 nattr_count = #attrs<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 id = obj.id<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 strAttrs=”<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 — \u5f00\u59cb\u8fc7\u6ee4\u663e\u793a\u6570\u636e\u5bf9\u8c61\u5c5e\u6027<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 for nIndex = 1, nattr_count do<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 strAttr = attrs[nIndex].attr<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 strValue = attrs[nIndex].value<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 strValue = strValue:gsub(“%%3Cbr%%3E”, “<br>”)<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 strValue = strValue:gsub(“&”, “\uff06”)<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 strItem = ‘{“attr”:”‘ .. strAttr .. ‘”,”value”:”‘ .. strValue .. ‘”},’<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 strAttrs = strAttrs .. strItem<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 end<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 — \u53d6\u6d88\u6700\u540e\u4e00\u4e2a,\u53f7<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 strAttrs = trim_laster_char(strAttrs)<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 strRow = ‘{“id”:”‘ .. id .. ‘”,”attrs”:[‘ .. strAttrs .. ‘]},’<\/div>\n\u00a0 \u00a0 \u00a0 \u00a0 strDataJson = strDataJson .. strRow<\/div>\n\u00a0 \u00a0 end<\/div>\n\u00a0 \u00a0 — \u53d6\u6d88\u6700\u540e\u4e00\u4e2a,\u53f7<\/div>\n\u00a0 \u00a0 strDataJson = trim_laster_char(strDataJson)<\/div>\n\u00a0 \u00a0 strDataJson = strDataJson .. ‘]’<\/div>\n<\/div>\n\u00a0 \u00a0 local strAction = ‘[{“action_type”:”reset_data_attr”,”value”:’ .. strDataJson .. ‘}]’<\/div>\n\u00a0 \u00a0 mobox.setAction(strLuaDEID, strAction)<\/div>\nend<\/div>\n<\/blockquote>\n\u8fd9\u4e2a\u5217\u5b50\u4e5f\u53ef\u4ee5\u7528\u4e8e\u522b\u7684\u4e00\u4e9b\u975e\u6cd5\u5b57\u7b26\u4e32\u7684\u5904\u7406<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"
\u6211\u4eec\u5728Gird\u5217\u51fa\u6570\u636e\u7684\u65f6\u5019\uff0c\u82e5\u6570\u636e\u5185\u5e26%3Cbr%3E\uff0c\u5176\u5b9e\u662f\u56de\u8f66\u7684\u610f\u601d\uff0c\u82e5grid\u8bfb\u51fa\u6570\u636e\u4e0d\u505a\u4efb\u4f55\u5904\u7406\uff0c\u90a3 […]<\/p>\n","protected":false},"author":1,"featured_media":2539,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,5,1],"tags":[31,14],"class_list":["post-2537","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-eckf","category-plmcenter","category-didaima","tag-didaima","tag-jiaoben"],"_links":{"self":[{"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/posts\/2537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/comments?post=2537"}],"version-history":[{"count":2,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/posts\/2537\/revisions"}],"predecessor-version":[{"id":2541,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/posts\/2537\/revisions\/2541"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/media\/2539"}],"wp:attachment":[{"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/media?parent=2537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/categories?post=2537"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/tags?post=2537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}