KikoPlayProject / KikoPlayApp

MIT License
2 stars 1 forks source link

removechild无法移除元素 #2

Closed tjljw2000 closed 2 days ago

tjljw2000 commented 4 days ago

代码如下

<gview content_margin="10,0,0,0">
    <vview content_margin="0,0,0,0" view-depend:stretch="3">
        <gview col-stretch="2:1" content_margin="0,0,0,0" >
            <label id="season_cover" view-depend:align="48" view-depend:col="1" view-depend:row="1" />
            <label id="season_desc" word_wrap="true" view-depend:col="2" view-depend:row="1" view-depend:align="21"/>
        </gview>
        <hview id="season_pager" spacing="0" content_margin="0,0,0,0" view-depend:row="2">
        </hview>
        <list id="ep_view"/>
        <button title="Back" event:click="detail.onBackBtnClk" view-depend:row="3"/>
    </vview>
</gview>
local refreshSeriesIndicator = function (series_info)
    local pager = kiko.ui.get("season_pager")
    local child = pager:getchild("page_btn")
    pager:removechild("page_btn")

    kiko.log(series_info)
    for index, value in ipairs(series_info["seasons"]) do
        local child = pager:addchild(string.format(
            "<button id=\"page_btn\" data:idx=\"%d\" title=\"%s\" checkable=\"true\" btn_group=\"season_btn\" />",
            index, "第" .. index .. "季 - " .. value["Name"]
        ))
        if index == 1 then
            child:setopt("checked", true)
        end
    end
end
Protostars commented 4 days ago

可以先确认下pager:getchild返回的是不是nil

tjljw2000 commented 3 days ago

重新测试了一下,返回的不是nil,元素可以被删掉,但是UI不会更新

<window title="App示例" w="450" h="400" content_margin="0,0,0,0" >
    <hview>
        <button title="Add Button" event:click="onAddBtnClick" />
        <button title="Remove Button" event:click="onRemoveBtnClick" />
    </hview>
    <hview id="season_paginator" spacing="0" content_margin="0,0,0,0" view-depend:row="2">
        <button id="to_be_remove" title="To Be Remove"/>
        <!-- here -->
    </hview>
</window>
app = {}

app.loaded = function(param)
    local w = param["window"]
    app.w = w
    w:show()
end

app.onRemoveBtnClick = function(param)
    local pager = kiko.ui.get("season_paginator")
    local child = pager:getchild("to_be_remove")
    if child then
        pager:removechild("to_be_remove")
        app.w:message("Removed")
    else
        app.w:message("It's nil")
    end
end

app.onAddBtnClick = function (param)
    local pager = kiko.ui.get("season_paginator")
    pager:addchild([[
        <button id="to_be_remove" title="To Be Remove"/>
    ]])
end
image

后两个是动态add的按钮

Protostars commented 2 days ago

已修复,可自行编译最新master,或者到群里下载编译好的文件