From bb379a2a645e8f7ac2e5ea5319c7f01d6c718854 Mon Sep 17 00:00:00 2001 From: zhangmx <1308646+zhangmx@users.noreply.github.com> Date: Fri, 10 Mar 2023 14:47:07 +0800 Subject: [PATCH] Add support for tabulator getSelectedData function --- node-red-node-ui-table/node.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/node-red-node-ui-table/node.js b/node-red-node-ui-table/node.js index 35eb462..c3d0718 100644 --- a/node-red-node-ui-table/node.js +++ b/node-red-node-ui-table/node.js @@ -287,13 +287,20 @@ module.exports = function (RED) { msg.payload.arguments=[]; } if (msg.payload.returnPromise) { - $scope.table[msg.payload.command].apply($scope.table,msg.payload.arguments).then(function(...args){ - $scope.send({topic:"success", ui_control: {callback:$scope.msg.payload.command}, return:$scope.msg.payload}); - }).catch(function(error){ - if (Object.keys(error).length>0) { - $scope.send({topic:"error", ui_control: {callback:$scope.msg.payload.command}, return:$scope.msg.payload, error: error}); + let commandReturn = $scope.table[msg.payload.command].apply($scope.table,msg.payload.arguments); + if (commandReturn) { + if (typeof commandReturn.then === "function") { + commandReturn.then(function(...args){ + $scope.send({topic:"success", ui_control: {callback:$scope.msg.payload.command}, return:$scope.msg.payload}); + }).catch(function(error){ + if (Object.keys(error).length>0) { + $scope.send({topic:"error", ui_control: {callback:$scope.msg.payload.command}, return:$scope.msg.payload, error: error}); + } + }); + } else { + $scope.send({topic:"success", ui_control: {callback:$scope.msg.payload.command}, return:$scope.msg.payload, payload:commandReturn}); } - }); + } } else { $scope.table[msg.payload.command].apply($scope.table,msg.payload.arguments); }