Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Adriano Fabri 469 posts 1633 karma points
    Mar 24, 2021 @ 17:35
    Adriano Fabri
    0

    Umbraco v8 - Angular - findIndex is not a function

    Hi, I'm trying to update a my custom package from umbraco v7 to v8

    In my controller I have the variable vm.JSONStructure with this content:

    {"name":"Configuration Manager","tabs":[{"id":1,"sectionName":"content","label":"CONTENT","alias":"afappContentTab","active":true,"actions":[{"action":"saving","doctypes":[{"doctypeAlias":"simplePage","properties":[{"propertyAlias":"title","config":{"propertyType":"string","propertyAliasToCopyValue":"Name","defaultValue":""}},{"propertyAlias":"date","config":{"propertyType":"datetime","propertyAliasToCopyValue":"CreateDate","defaultValue":""}}]}]}]},{"id":2,"sectionName":"media","label":"MEDIA","alias":"afappMediaTab","active":false,"actions":[{"action":"saving","doctypes":[{"doctypeAlias":null,"properties":null}]}]}]}
    

    In my controller I also have this function that add a new doctype in the vm.JSONStructure variable:

    vm.AddNewDocType = function (sectionAlias, actionAlias) {
        vm.sectionPosition = vm.JSONStructure.findIndex(s => s.sectionName === sectionAlias);
        vm.actionPosition = vm.JSONStructure[vm.sectionPosition].actions.findIndex(a => a.action === actionAlias);
        vm.JSONStructure[vm.sectionPosition].actions[vm.actionPosition].doctypes.push({ "doctypeAlias": "", "properties": [{ "propertyAlias": "", "config": { "propertyType": "", "propertyAliasToCopyValue": "", "defaultValue": "" } }] });
        };
    

    With Umbraco v7 the findIndex method worked properly.

    With Umbraco v8 instead I receive this error:

    TypeError: vm.JSONStructure.findIndex is not a function
    at AFAPPJSONConfig.vm.AddNewDocType (afapp.controller.js?cdv=1:61)
    at fn (eval at compile (angular.js?cdv=1:16486), <anonymous>:4:409)
    at callback (angular.js?cdv=1:29019)
    at Scope.$eval (angular.js?cdv=1:19461)
    at Scope.$apply (angular.js?cdv=1:19560)
    at HTMLAnchorElement.<anonymous> (angular.js?cdv=1:29023)
    at HTMLAnchorElement.dispatch (jquery.min.js?cdv=1:2)
    at HTMLAnchorElement.v.handle (jquery.min.js?cdv=1:2)
    -----------------------------------------------------------
    
    Where line 61 is the following line of my code:
    
    vm.sectionPosition = vm.JSONStructure.findIndex(s => s.sectionName === sectionAlias);
    

    What's changed from Umbraco v7 to v8 and how can I solve the problem?

    Thanks for the support Adriano

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Mar 24, 2021 @ 20:13
    Marc Goodson
    2

    Hmmm Adriano hmmm

    findIndex is not a function

    is usually an indication that the object isn't an array...

    I'm not sure what your Json Structure would have been in V7, but in the snippet you've posted, wouldn't it be the "tabs" property you'd need to be using findIndex on?

    it's those elements within "tabs" that seem to be an array which have the 'sectionName' to filter by?

    regards

    Marc

  • Adriano Fabri 469 posts 1633 karma points
    Mar 25, 2021 @ 16:24
    Adriano Fabri
    0

    Hi Marc, damn...you are right!!! :-)

    I forgot that for the new version I have slightly modified the original json structure (I'm very embarrassed)

    ok...my mistake!!!

    Thanks

    A.

Please Sign in or register to post replies

Write your reply to:

Draft