<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p class="p1" style="margin-top: 0px; margin-bottom: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 15px; line-height: normal; font-family: "Helvetica Neue"; white-space: normal;">在Magento 2中,UI组件的XML文件必须包含一个声明,以指定XML版本和编码格式。以下是一个示例XML声明:</p><pre class="brush:as3;toolbar:false"><?xml version="1.0" encoding="UTF-8"?></pre><p class="p1" style="margin-top: 0px; margin-bottom: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 15px; line-height: normal; font-family: "Helvetica Neue"; white-space: normal;">其中,version属性指定XML版本,encoding属性指定编码格式。在Magento 2中,通常使用UTF-8编码格式。</p><p class="p1" style="margin-top: 0px; margin-bottom: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 15px; line-height: normal; font-family: "Helvetica Neue"; white-space: normal;">以下是一个完整的UI组件的XML配置示例,其中包括了声明和组件的基本配置:</p><pre class="brush:as3;toolbar:false"><?xml version="1.0" encoding="UTF-8"?> <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> <argument name="data" xsi:type="array"> <item name="js_config" xsi:type="array"> <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item> </item> <item name="spinner" xsi:type="string">my_module_loading</item> </argument> <dataSource name="my_module_data_source"> <argument name="dataProvider" xsi:type="configurableObject"> <argument name="class" xsi:type="string">My\Module\Model\DataProvider</argument> <argument name="name" xsi:type="string">my_module_data_source</argument> <argument name="primaryFieldName" xsi:type="string">id</argument> <argument name="requestFieldName" xsi:type="string">id</argument> </argument> </dataSource> <columns name="my_module_columns"> <column name="id" class="My\Module\Ui\Component\Listing\Column\Id"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="sorting" xsi:type="string">asc</item> <item name="label" xsi:type="string" translate="true">ID</item> </item> </argument> </column> <column name="name" class="My\Module\Ui\Component\Listing\Column\Name"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="sorting" xsi:type="string">asc</item> <item name="label" xsi:type="string" translate="true">Name</item> </item> </argument> </column> </columns> <listingToolbar name="listing_top"> <settings> <sticky>true</sticky> </settings> <filters name="listing_filters"> <filterSelect name="store_id" provider="${ $.parentName }"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="caption" xsi:type="string" translate="true">--Select Store--</item> <item name="dataScope" xsi:type="string">store_id</item> <item name="label" xsi:type="string" translate="true">Store</item> <item name="placeholder" xsi:type="string" translate="true">All Store Views</item> </item> </argument> </filterSelect> </filters> </listingToolbar> </listing></pre><p class="p2" style="margin-top: 0px; margin-bottom: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 15px; line-height: normal; font-family: "PingFang SC"; white-space: normal;">在这个示例中,<span class="s1" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";">XML</span>文件包含了<span class="s1" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";">UI</span>组件的基本配置信息,包括数据源、列、列表工具栏等</p><p><br/></p>