你需要的参数设定值render_url上insertListing,然后更新您的数据提供的这个URL里面。有必要执行两次此操作,因为您将需要为表单组件提供一个数据提供程序,并为清单组件提供一个特定的数据提供程序。
1-正确声明
insertListing 组件:(供应商/模块/视图/adminhtml/ui_component/vendor_module_form.xml)
<insertListing name="testInsertListing">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataLinks" xsi:type="array">
<item name="imports" xsi:type="boolean">false</item>
<item name="exports" xsi:type="boolean">true</item>
</item>
<item name="autoRender" xsi:type="boolean">true</item>
<!-- the namespace attribute should be the name of the listing XML file -->
<item name="ns" xsi:type="string">vendor_module_listing</item>
<!-- This is the default render_url. We are going to update this value
in the DataProvider -->
<item name="render_url" xsi:type="url" path="mui/index/render"/>
<!-- Here we add the parameters that we want to add to the render_url. -->
<item name="filter_url_params" xsi:type="array">
<!-- You can add as many as you want -->
<item name="id" xsi:type="string">*</item>
</item>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">id</item>
</item>
</item>
</argument>
</insertListing>
2-将以下更改添加到“表单”页面的“数据提供程序”。通过将参数“ id”添加到URL的末尾,将更改render_url:
(供应商/模块/ Ui / DataProvider / [路径到您的数据提供者.php])
- 添加RequestInterface类:
- 在数据提供者类上声明属性$ request。
- 向__construct方法添加一个RequestInterface对象;调用prepareUpdateUrl()方法。
- 将prepareUpdateUrl()添加到您的类中:
注意:请勿在数据提供者上复制/粘贴下面的整个块。相反,请选择代码中缺少的部分
<?php use Magento\Framework\App\RequestInterface;
use Magento\Framework\UrlInterface;
class MyListingDataProvider extends AbstractDataProvider
{
protected $data;
protected $meta;
protected $collection;
protected $urlBuilder;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
UrlInterface $urlBuilder,
array $meta = [],
array $data = []
)
{
$this->collection = $collection;
$this->data = $data;
$this->meta = $meta;
$this->request = $request;
$this->urlBuilder = $urlBuilder;
$this->prepareUpdateUrl();
parent::__construct($name, $primaryFieldName, $requestFieldName, $this->meta, $data);
}
protected function prepareUpdateUrl()
{
$id = $this->request->getParam('id');
$this->meta = array_replace_recursive(
$this->meta,
[
'testInsertListing' =>
['arguments' => [
'data' => [
'config' => [
'render_url' => $this->urlBuilder
->getUrl('mui/index/render/id/' . $id),
'update_url' => $this->urlBuilder->getUrl('mui/index/render/id/' . $id)
]
],
]
]
]
);
}
//Implement the other methods you need
}
3-更新您的列表组件。它必须在DataSource组件内部具有updateUrl参数:
(供应商/模块/视图/adminhtml/ui_component/vendor_module_listing.xml)
<?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="provider" xsi:type="string">
vendor_module_listing.module_listing_data_source
</item>
</item>
</argument>
<settings>
<spinner>vendor_module_listing_columns</spinner>
<deps>
<dep>vendor_module_listing.module_listing_data_source</dep>
</deps>
</settings>
<dataSource name="module_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Vendor\Module\Ui\DataProvider\[name-of-your-listing-data-provider-class]</argument>
<argument name="name" xsi:type="string">module_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">id</item>
</item>
<!-- fields to be added to the URL when retrieving the data -->
<item name="filter_url_params" xsi:type="array">
<item name="id" xsi:type="string">*</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<columns name="vendor_module_listing_columns">
<!-- Declare your columns here -->
</columns>
</listing>
4-更新您的清单数据提供程序以更改上述清单组件上的updateUrl
(供应商/模块/ Ui / DataProvider / [路径到您的LISTING-data-provider.php])
注意:请勿在数据提供者上复制/粘贴下面的整个块。相反,请选择代码中缺少的部分
<?php
use Magento\Framework\App\RequestInterface;
class MyListingDataProvider extends AbstractDataProvider
{
protected $request;
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
Collection $collection,
RequestInterface $request,
array $meta = [],
array $data = []
)
{
$this->collection = $collection;
$this->request = $request;
$this->data = $data;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->prepareUpdateUrl();
}
protected function prepareUpdateUrl()
{
if (!isset($this->data['config']['filter_url_params'])) {
return;
}
foreach ($this->data['config']['filter_url_params']
as $paramName => $paramValue) {
if ('*' == $paramValue) {
$paramValue = $this->request->getParam($paramName);
}
if ($paramValue) {
$this->data['config']['update_url'] = sprintf(
'%s%s/%s/',
$this->data['config']['update_url'],
$paramName,
$paramValue
);
}
}
}
//Get the parameter "id" inside of the getData() method:
public function getData()
{
$item_id = $this->request->getParam('id');
//Apply a filter to your collection using $item_id
/**
Return your data in the appropriate format
$totalRecords should be an integer
$items should be an array
*/
return array('totalRecords' => $totalRecords, 'items' => $items);
}
}
让我知道您是否还有任何问题。我可能无法回答评论,但可以更新答案。