How to add many <row> components in ZK in specific position

不打扰是莪最后的温柔 提交于 2020-01-04 07:51:21

问题


I'm working in a ZK application and I need to add <row>'s components based on user input. The zul is like this:

<grid id="mygrid">
    <rows id="rows">
        <row>
            <cell>
                <label value="Rows to add 1:"/>
            </cell>
            <cell>
                <textbox id="txt_addRows1"/>
            </cell>
        </row>

        <!-- Here I need to add rows specified in txt_addRows1 -->

        <row>
            <cell>
                <label value="Rows to add 2:"/>
            </cell>
            <cell>
                <textbox id="txt_addRows2"/>
            </cell>
        </row>

        <!-- Here I need to add rows specified in txt_addRows2 -->

        <row align="right">
            <cell colspan="2">
                <button id="btn_generate" label="Generate"/>
            </cell>
        </row>
    </rows>
</grid>

In the composer I can do something like:

Row someRow = new Row();
row.setParent(rows);

My question is: how do I specify that the new row (generated programmatically in the composer) to be rendered in the specified places and not others?

Any suggestion/guide is also welcomed. Thanks in advance for your answers.


回答1:


There are 2 ways to insert something in the DOM.
First way is to set the parent, the second one is adding a child.

If you check the AbstractComponent api. you see they also speak of appendChild and insertBefore(Component newChild, Component refChild)

So the code would look like :

rows.insertBefore(newRow,rowWhatComesAfterYourRow);


来源:https://stackoverflow.com/questions/49264338/how-to-add-many-row-components-in-zk-in-specific-position

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!