Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with arrays in recursive models #70

Open
mellis481 opened this issue Aug 8, 2018 · 1 comment
Open

Working with arrays in recursive models #70

mellis481 opened this issue Aug 8, 2018 · 1 comment

Comments

@mellis481
Copy link

Functionality exists to specify the path to arrays in your model in the X2JS options. This prevents an array with a single item from being serialized as an object instead of an array. Code-wise, this is accomplished with the following where Items is an array in MyXml:

 var x2js = new X2JS({
        arrayAccessFormPaths : [
           "MyXml.Items"
        ]
    });

How this is accomplished with a recursive model, though? Using Typescript to give an example:

interface MyEntity {
    id: string;
    name: string;
    children: MyEntity[];
}

In this example, you would have potentially unlimited arrayAccessFormPaths values to account for all the levels of children in MyEntity. Eg.

 var x2js = new X2JS({
        arrayAccessFormPaths : [
           "MyEntity.children",
           "MyEntity.children.children",
           "MyEntity.children.children.children",
           "MyEntity.children.children.children.children",
           "MyEntity.children.children.children.children.children",
           ...
        ]
    });
@mellis481
Copy link
Author

I also attempted to use regex arrayAccessFormPaths values, but it does not seem to process them correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant