Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Home-made collection
Message
De
05/08/2017 04:02:21
 
 
Information générale
Forum:
AngularJS
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01653087
Message ID:
01653093
Vues:
52
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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform