From cdffe69a68e0d432adfaac094fc1156fbb893725 Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 13 Sep 2023 13:55:07 +0800 Subject: [PATCH] * testtask: refactor the ajaxGetTestReports method. --- module/testtask/control.php | 13 ++++++------- module/testtask/js/common.ui.js | 7 +++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/module/testtask/control.php b/module/testtask/control.php index 15eeb87a8a..44ea5ea449 100644 --- a/module/testtask/control.php +++ b/module/testtask/control.php @@ -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)); } /** diff --git a/module/testtask/js/common.ui.js b/module/testtask/js/common.ui.js index 256a73d33b..6226edfa34 100644 --- a/module/testtask/js/common.ui.js +++ b/module/testtask/js/common.ui.js @@ -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'}); } });