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

nested object rendering #81

Closed
tpaz opened this issue Mar 4, 2014 · 14 comments
Closed

nested object rendering #81

tpaz opened this issue Mar 4, 2014 · 14 comments

Comments

@tpaz
Copy link

tpaz commented Mar 4, 2014

Hi.
I found it as tough constraint that I can't pass nested objects into the riot template renderer.
Consider a simple two levels of nested object such as the following model object ("data" is just for initialization from store for example):

function Items(data) {
this.name = data.name;
this.price = data.price;
this.details = { 'id': data.details.id, 'image': data.details.image }
...
}

When tested with a template, only the flat properties (such as name and price) would work for me, but the nested ones like so: details.id - would not.
when I looked at the renderer function (regex) I realized it won't work since it does not expect a dot nor a key['name'] format.

Thoughts?
Must I use only Flat properties in model? in other frameworks of-course it is possible.
I don't think it would break the constraint mentioned in Riot blog about the architecture of flat templates to have nested variables. it is not adding any logic

TIA
Tomer

@tipiirai
Copy link
Contributor

tipiirai commented Mar 4, 2014

This is a decent request. Probably need to implement it. Thanks!

@tpaz
Copy link
Author

tpaz commented Mar 4, 2014

of-course it might somewhat risk the renderer current performance though ;)

@tipiirai
Copy link
Contributor

tipiirai commented Mar 4, 2014

Yeah. However this doesn't sound too heavy and is useful. I've had the same need as well.

@tpaz
Copy link
Author

tpaz commented Mar 4, 2014

great. looking forward then... (I'm afraid to touch that black magic regex function myself :))

potomak added a commit to fork-n-roll/riotjs that referenced this issue Mar 4, 2014
@tipiirai
Copy link
Contributor

tipiirai commented Mar 5, 2014

Seems @potomak did the job already! Support for nested objects is now there. Enjoy!

@tipiirai tipiirai closed this as completed Mar 5, 2014
@tpaz
Copy link
Author

tpaz commented Mar 8, 2014

Hi. Tried to use the fix but doesn't seem to work?! :( I get literally the "{obj.property}" string rather than the value.

@tipiirai
Copy link
Contributor

tipiirai commented Mar 9, 2014

@potomak can you check the above? Thank you!

@potomak
Copy link
Contributor

potomak commented Mar 9, 2014

@tipiirai @tpaz I don't see any error, see http://jsbin.com/dezazate/1/edit
I also added a test case for the feature that is passing without errors, see https://github.com/fork-n-roll/riotjs/blob/c3f60ddd09bd46a4374ef49df0163bbb23215d25/test/render_test.js#L67-L69

@tpaz
Copy link
Author

tpaz commented Mar 9, 2014

@potomak yes I saw the assertion test. yet in my environment it failed. Sample works indeed. It was a problem in my environment. works charms now :)

@fernandoacorreia
Copy link

This is very useful. In my usage I also found this limitation to be too big a nuisance. Thanks for fixing.

@tipiirai
Copy link
Contributor

Yeah. Seems to perform well and doesn't add any logic on the template layer.

@mgustafsson1
Copy link

Hi @potomak - is it possible to use key['property'], e.g. person['firstName'] as per your example, too? I'm guessing not, just posting here to make sure I'm not using it wrong :)

@potomak
Copy link
Contributor

potomak commented May 1, 2014

@mgustafsson1 no you can't, you can use only . to reference object properties right now.

@mgustafsson1
Copy link

@potomak That was quick, thank you! Will use dot notation only for now.

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

5 participants