Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Home-made collection
Message
From
05/08/2017 04:02:21
 
General information
Forum:
AngularJS
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01653087
Message ID:
01653093
Views:
53
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everybody,
>
>I'm working on a relatively complex form. It has a main item row and it may have collections of related matrix rows. I'm trying to implement my own collection in JavaScript.
>
>This is the piece of code I'm working on right now
>
>
>$scope.matrixAttributesChanged = function (rowId, columnId) {
>            log.debug("matrixAttributesChanged - rowId=" + rowId + " columnId=" + columnId);
>            let inventoryMatrix = undefined;
>            let index = undefined;
>
>            if (rowId && columnId) {
>                let key = rowId.toString() + "|" + columnId.toString();
>                if (changedInventoryObjects.length > 0) {
>                    log.debug("changedInventoryObjects contains changed inventory objects already");
>
>                    // Search for that object already in the array
>                    index = changedInventoryObjects.findIndex(x => x.index == key);
>                    if (index >= 0) {
>                       inventoryMatrix  = Object.assign({}, changedInventoryObjects[index].inventoryObject);
>                    }
>                }
>                
>                if (inventorySaveCheck()) {
>                    $scope.form.editRetailForm.editRetailMatrixForm.$setPristine();
>                    let clone = Object.assign({}, $scope.currentIitem);
>
>                    changedInventoryObjects.push({
>                        index: key,
>                        inventoryObject: clone
>                    }); // make collection of changed matrix inventory objects
>                }
>
>                
>                if (inventoryMatrix) {
>                    $scope.currentIitem = inventoryMatrix;
>                }
>                else {
>                    log.debug("Getting inventory row...");
>                    services.IItem.getByItemIdAndAttributes($scope.currentItem.itemId, rowId, columnId).
>                        then(function (results) {
>
>                            $scope.currentIitem = results;
>                            $scope.currentIitem.rowValueId = rowId;
>                            $scope.currentIitem.columnValueId = columnId;
>                            if ($scope.currentIitem.inventId == 0) {
>                                $scope.currentIitem.itemId = $scope.currentItem.itemId;
>                                $scope.currentIitem.department = $scope.currentItem.department;
>                                $scope.currentIitem.category = $scope.currentItem.category;
>                                $scope.currentIitem.item = $scope.currentItem.item;
>                                $scope.currentIitem.descrip = getMatrixDescription(rowId, columnId);
>                            }
>
>                            // log.debug($scope.currentIitem);
>
>                        });
>                }
>            }                
>        }
>
>Does it look like OK implementation?
>
>The question I have - if I found my item in collection already, I want to replace my current object in collection with the more recent copy of it. What would you suggest?

splice().

Looks to me that, if currentIitem is meant to point to an existing item in a collection, then '$scope.currentlitem = results' will break that assumption?

>
>Thanks in advance.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform