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

Access sub-attribute via dot notation ("address.street") #525

Closed
Xennis opened this issue Jun 23, 2015 · 4 comments
Closed

Access sub-attribute via dot notation ("address.street") #525

Xennis opened this issue Jun 23, 2015 · 4 comments

Comments

@Xennis
Copy link
Contributor

Xennis commented Jun 23, 2015

Hey,

my API returns data in the format (extract only):

[
        {
            "id": 1,
            "address": {
                "street": "Heidberg",
                 "postal_code": "75385"
            }
        },
        {
            "id": 2,
            "address": {
                "street": "Heinrich-Böll-Str.",
                "postal_code": "70707"
            }
        },
        ...
]

How can I access for instance the street attribute? It would be nice, if I could access it directly by nga.field('address.street'), but that does not seems to work. Of course I could define the field as template field and write a directive. But when I've many of such fields, that would not be so nice. Or is there another, simple way?

@karantan
Copy link

I think this is what you are looking for:

app.config(function(RestangularProvider) {
    RestangularProvider.addElementTransformer('books', function(element) {
        for (var key in element.values) {
            element[key] = element.values[key];
        }

        return element;
    });
});

I copy paste this from the documentation

@jpetitcolas
Copy link
Contributor

Indeed, we can do it currently the way @karantan suggested. ng-admin doesn't support the dot notation. But that's indeed a good idea. I keep the issue opened to not forget it. :)

@jpetitcolas jpetitcolas changed the title Access interconnected attribute Access sub-attribute via dot notation ("address.street") Jun 24, 2015
@fzaninotto
Copy link
Member

Related to #68 and #390

@fzaninotto
Copy link
Member

Good news: that's now possible in the master branch, thanks to #549 being merged.

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

No branches or pull requests

4 participants