1

我在我的模块中创建了一个自定义选项卡并成功显示了一个网格输出,但我的问题是我们如何在一页中显示两个网格序列化程序块?我试图用这段代码调用两个序列化程序块。

public function customgridAction()

{
   $this->loadLayout();
    $this->getLayout()->getBlock('regionpage.productgrid')->setProductsGrid($this->getRequest()->getPost('products_grid', null));
    $this->getLayout()->getBlock('regionpage.articlegrid')->setArticlesGrid($this->getRequest()->getPost('articles_grid', null));
    $this->renderLayout();
}

这就是我的布局 xml 的样子

<regionpage_adminhtml_regionpage_customgrid>
<block type="core/text_list" name="root">
    <block type="regionpage/adminhtml_regionpage_edit_tab_productgrid" name="regionpage.productgrid"/>
    <block type="adminhtml/widget_grid_serializer" name="regionpage_productgrid">
        <reference name="regionpage_productgrid">
            <action method="initSerializerBlock">
                <grid_block_name>regionpage.productgrid</grid_block_name>
                <data_callback>getSelectedProducts</data_callback>
                <hidden_input_name>links[productgrid]</hidden_input_name>
                <reload_param_name>products_grid</reload_param_name>
            </action>
            <action method="addColumnInputName">
                <input_name>position</input_name>
            </action>
        </reference>
    </block>
</block>

 <regionpage_adminhtml_regionpage_customgrid>
    <block type="core/text_list" name="root">
        <block type="regionpage/adminhtml_regionpage_edit_tab_articlegrid" name="regionpage.articlegrid"/>
        <block type="adminhtml/widget_grid_serializer" name="regionpage_articlegrid">
            <reference name="regionpage_articlegrid">
                <action method="initSerializerBlock">
                    <grid_block_name>regionpage.articlegrid</grid_block_name>
                    <data_callback>getSelectedArticles</data_callback>
                    <hidden_input_name>links[articlegrid]</hidden_input_name>
                    <reload_param_name>articles_grid</reload_param_name>
                </action>
                <action method="addColumnInputName">
                    <input_name>position</input_name>
                </action>
            </reference>
        </block>
    </block>
 </regionpage_adminhtml_regionpage_customgrid>

但它输出最后一个块而不是两个块。

4

1 回答 1

1

好吧,我想我已经破解了。

问题似乎是当您使用包装块时

<block type="core/text_list" name="root">

一旦您定义了一个名称为“root”的块,如果稍后出现另一个具有相同名称的块,它将被覆盖。(如果我错了请纠正我)

您可以尝试两种解决方案。

  1. 将两个 xml 合并为一个部分

这将使您的xml如下

<regionpage_adminhtml_regionpage_customgrid>
    <block type="core/text_list" name="root">
    <block type="regionpage/adminhtml_regionpage_edit_tab_productgrid" name="regionpage.productgrid"/>
    <block type="adminhtml/widget_grid_serializer" name="regionpage_productgrid">
        <reference name="regionpage_productgrid">
            <action method="initSerializerBlock">
                <grid_block_name>regionpage.productgrid</grid_block_name>
                <data_callback>getSelectedProducts</data_callback>
                <hidden_input_name>links[productgrid]</hidden_input_name>
                <reload_param_name>products_grid</reload_param_name>
            </action>
            <action method="addColumnInputName">
                <input_name>position</input_name>
            </action>
        </reference>
    </block>
    <block type="regionpage/adminhtml_regionpage_edit_tab_articlegrid" name="regionpage.articlegrid"/>
        <block type="adminhtml/widget_grid_serializer" name="regionpage_articlegrid">
            <reference name="regionpage_articlegrid">
                <action method="initSerializerBlock">
                    <grid_block_name>regionpage.articlegrid</grid_block_name>
                    <data_callback>getSelectedArticles</data_callback>
                    <hidden_input_name>links[articlegrid]</hidden_input_name>
                    <reload_param_name>articles_grid</reload_param_name>
                </action>
                <action method="addColumnInputName">
                    <input_name>position</input_name>
                </action>
            </reference>
        </block>
    </block>
</regionpage_adminhtml_regionpage_customgrid>
  1. 在第二部分中简单地替换以下部分

使用参考节点,这将使您的第二部分看起来像

<regionpage_adminhtml_regionpage_customgrid>
    <reference name="root">
    <block type="regionpage/adminhtml_regionpage_edit_tab_articlegrid" name="regionpage.articlegrid"/>
        <block type="adminhtml/widget_grid_serializer" name="regionpage_articlegrid">
            <reference name="regionpage_articlegrid">
                <action method="initSerializerBlock">
                    <grid_block_name>regionpage.articlegrid</grid_block_name>
                    <data_callback>getSelectedArticles</data_callback>
                    <hidden_input_name>links[articlegrid]</hidden_input_name>
                    <reload_param_name>articles_grid</reload_param_name>
                </action>
                <action method="addColumnInputName">
                    <input_name>position</input_name>
                </action>
            </reference>
        </block>
    </reference>
</regionpage_adminhtml_regionpage_customgrid>

这是一个magento堆栈交换答案https://magento.stackexchange.com/questions/3376/grid-layout-in-magento/3804#3804

于 2013-05-28T05:04:49.813 回答