簡體   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