案例中心 视频中心

lua 对回车(%3Cbr%3E)处理方法 lua 对回车(%3Cbr%3E)处理方法

lua 对回车(%3Cbr%3E)处理方法

分类:二次开发 产品中心 低代码 41

我们在Gird列出数据的时候,若数据内带%3Cbr%3E,其实是回车的意思,若grid读出数据不做任何处理,那么就会影响系统表达

为了解决这个问题,我们可以编辑一个lua脚本,将这个数据做处理后再显示(在显示前事件里面定义这个lua脚本)

脚本列子

–[[
    功能说明:
        1) 显示前做一些字段的处理
        2)前端导入,新增有换行符号 %%3Cbr%%3E  ,替换成 <br> 前端html支持的换行内容
        3)内容中有&,替换成 & 前端解析 &不支持,最好在输入时进行替换
–]]
json = require(“json”)
mobox = require(“OILua_JavelinExt”)
require(“oi_basestrfunc”)
function BeforeGridShow(strLuaDEID)
    local nRet, strRetInfo
    local arobjs, attrs, success
    — 获取输入的DataJson数据包
    nRet, strRetInfo = mobox.getCurEditDataPacket(strLuaDEID)
    if (nRet ~= 0) then
        mobox.error(strLuaDEID, “无法获取数据包!”)
        return
    end
    if (strRetInfo == ” or strRetInfo == nil) then
        return
    end
    — 解析数据包,数据包格式
    — [{“id”:””,”attrs”:[{“attr”:””,”value”:””},..]},..]
    local n, nCount
    success, arobjs = pcall(json.decode, strRetInfo)
    if (success == false) then
        mobox.error(strLuaDEID, “非法的JSON格式!”)
        return
    end
    nCount = #arobjs
    if (nCount == 0) then
        return
    end
    local obj, attrs
    local nattr_count
    local strRow, strAttr, strItem
    local strDataJson
    local id, strValue
    local strAttrs
    strDataJson = ‘[‘
    local seg = {}
    local nSegCount = 0
    for n = 1, nCount do
        obj = arobjs[n]
        attrs = obj.attrs
        nattr_count = #attrs
        id = obj.id
        strAttrs=”
        — 开始过滤显示数据对象属性
        for nIndex = 1, nattr_count do
            strAttr = attrs[nIndex].attr
            strValue = attrs[nIndex].value
            strValue = strValue:gsub(“%%3Cbr%%3E”, “<br>”)
            strValue = strValue:gsub(“&”, “&”)
            strItem = ‘{“attr”:”‘ .. strAttr .. ‘”,”value”:”‘ .. strValue .. ‘”},’
            strAttrs = strAttrs .. strItem
        end
        — 取消最后一个,号
        strAttrs = trim_laster_char(strAttrs)
        strRow = ‘{“id”:”‘ .. id .. ‘”,”attrs”:[‘ .. strAttrs .. ‘]},’
        strDataJson = strDataJson .. strRow
    end
    — 取消最后一个,号
    strDataJson = trim_laster_char(strDataJson)
    strDataJson = strDataJson .. ‘]’
    local strAction = ‘[{“action_type”:”reset_data_attr”,”value”:’ .. strDataJson .. ‘}]’
    mobox.setAction(strLuaDEID, strAction)
end
这个列子也可以用于别的一些非法字符串的处理
标签:低代码脚本 上一篇: 下一篇:
展开更多
预约软件体验

loading...