* testtask: refactor the ajaxGetTestReports method.

This commit is contained in:
liugang
2023-09-13 13:55:07 +08:00
parent b56ee9ca03
commit cdffe69a68
2 changed files with 9 additions and 11 deletions
+6 -7
View File
@@ -1453,7 +1453,8 @@ class testtask extends control
}
/**
* Ajax: Get test report by productID.
* 获取一个产品下的测试报告键值对。
* Get test report key-value pairs of a product by ajax.
*
* @param int $productID
* @access public
@@ -1461,13 +1462,11 @@ class testtask extends control
*/
public function ajaxGetTestReports(int $productID)
{
/* Testreport list. */
$testReportPairs = $this->loadModel('testreport')->getPairs($productID);
$reports = array();
$pairs = $this->loadModel('testreport')->getPairs($productID);
foreach($pairs as $id => $title) $reports[] = array('text' => $title, 'value' => $id);
$items = array();
foreach($testReportPairs as $testReportID => $testReportName) $items[] = array('text' => $testReportName, 'value' => $testReportID);
return print(json_encode($items));
return $this->send(array('result' => 'success', 'reports' => $reports));
}
/**
+3 -4
View File
@@ -55,13 +55,12 @@ function loadExecutionBuilds()
*/
function loadTestReports(productID)
{
$.get($.createLink('testtask', 'ajaxGetTestReports', 'productID=' + productID), function(data)
$.getJSON($.createLink('testtask', 'ajaxGetTestReports', 'productID=' + productID), function(result)
{
let $testreportPicker = $('[name="testreport"]').zui('picker');
if(data)
if(result.reports)
{
data = JSON.parse(data);
$testreportPicker.render({items: data});
$testreportPicker.render({items: result.reports});
$testreportPicker.$.changeState({value: '0'});
}
});