Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Home-made collection
Message
 
 
À
05/08/2017 04:02:21
Information générale
Forum:
AngularJS
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01653087
Message ID:
01653097
Vues:
48
>>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.

That's why instead of just pointing I am making a clone of the object when adding to the collection of changed objects. So, suppose we got the object originally, changed it, opened another object, changed it too, then tried to look at the first one and made more changes to it - now I need to replace that. The way I currently do it is finding that object in array, make a copy of my current row (clone) and then just use the assignment to replace with that copy.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform