繁体   English   中英

如何在Camunda中处理可变数量的过程变量

[英]How to handle variable number of process variables in Camunda

我是Camunda的新手,没有找到任何教程或参考资料来解释如何实现以下目标:

当开始一个过程时,我希望用户在发票中添加任意数量的项目。 在下一个用户任务上,所有这些项目及其数量应打印给批准数据的人。

我还不了解如何在流程及其变量之间建立这种1:n关系。 我需要为每个项目启动子流程吗? 还是我必须使用自定义Java对象? 如果是这样,我如何从任务列表中将表单元素映射到这样的对象?

我在Thorben提供的链接的帮助下工作了。

诀窍是使用JSON过程变量来存储更复杂的数据结构。 我在“开始事件”中初始化了此类列表。 这可以以某种形式或在我的情况下在侦听器中完成:

execution.setVariable("items", Variables.objectValue(Arrays.asList(dummyItem)).serializationDataFormat("application/json").create());

请注意,我添加了一个dummyItem,因为空列表将在序列化期间丢失其类型信息。

接下来,在我的自定义表单中,我加载此列表,并可以添加/删除项目。 使用camForm回调可以保留列表。

<form role="form" name="form">
    <script cam-script type="text/form-script">
    /*<![CDATA[*/
    $scope.items = [];

    $scope.addItem = function() {
        $scope.items.push({name: '', count: 0, price: 0.0});
    };

    $scope.removeItem = function(index) {
        $scope.items.splice(index, 1);
    };

    camForm.on('form-loaded', function() {
        camForm.variableManager.fetchVariable('items');
    });

    // variables-fetched is not working with "saved" forms, so we need to use variables-restored, which gets called after variables-fetched
    camForm.on('variables-restored', function() {
        $scope.items = camForm.variableManager.variableValue('items');
    });

    camForm.on('store', function() {
        camForm.variableManager.variableValue('items', $scope.items);
    });
    /*]]>*/
    </script>


    <table class="table">
        <thead>
            <tr><th>Name</th><th>Count</th><th>Price</th><th></th></tr>
        </thead>
        <tbody>
            <tr ng-repeat="i in items">
                <td><input type="text" ng-model="i.name"/></td>
                <td><input type="number" ng-model="i.count"/></td>
                <td><input type="number" ng-model="i.price"/></td>
                <td>
                    <button class="btn btn-default" ng-click="removeItem($index)">
                        <span class="glyphicon glyphicon-minus"></span>
                    </button>
                </td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td colspan="4">
                    <button class="btn btn-default" ng-click="addItem()">
                        <span class="glyphicon glyphicon-plus"></span>
                    </button>
                </td>
            </tr>
        </tfoot>
    </table>

</form>

两件事还没有解决:

  • 字段验证,例如用于数字字段
  • 添加/删除行时,“保存”按钮上使用的脏标志不会更新

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM