8000 Unable to reference nested data in nuemark attributes · Issue #559 · nuejs/nue · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Unable to reference nested data in nuemark attributes #559

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

Open
sturnclaw opened this issue Apr 22, 2025 · 3 comments
Open

Unable to reference nested data in nuemark attributes #559

sturnclaw opened this issue Apr 22, 2025 · 3 comments
Labels
nuekit Related to nuekit package

Comments

@sturnclaw
Copy link

Describe the Bug

When attempting to pass data to nuemark tags via attribute bindings (e.g :data="my_data"), the entire attribute string is treated as a single string key, preventing the use of nested data from the site/application YAML files.

This prevents a natural structuring of data within the site.yaml files, and given there is no built-in way to load application data from any other source, creates issues with name pollution/collision with Nue-reserved keys inside the site.yaml file.

Environment

OS: Linux
Nuekit: 1.0.0-RC3

Minimal Reproduction

# site.yaml
nested:
  data:
    - My Data Item: here
<!-- index.md -->

[my-custom-component :data="nested.data"]
@nobkd nobkd added the nuekit Related to nuekit package label Apr 22, 2025
@nobkd
Copy link
Collaborator
nobkd commented Apr 25, 2025

I think it's trying to access a key named "nested.data" not nested -> data atm. Should be fixed

@nobkd
Copy link
Collaborator
nobkd commented Apr 27, 2025

Yeah... I was right about that:

// :rows="pricing" --> rows -> all_data.pricing
function extractData(data, all_data) {
for (const key in data) {
if (key.startsWith(':')) {
data[key.slice(1)] = all_data[data[key]]
delete data[key]
}
}
return data
}


I'll try taking a look this week, if I find the time, but if anyone's interested, feel free to take this on.


I just did a quick stab at it using eval, which works, but this can still fail in some cases, so I'm hoping we don't neeed it:

-       data[key.slice(1)] = all_data[data[key]] 
+       data[key.slice(1)] = eval(`all_data.${data[key]}`)

@sturnclaw
Copy link
Author

...you could also just split the key by '.' and recursively descend into the object, but if this code isn't executed at runtime and you're not worried about injection attacks then the eval method would allow for array access as well I suppose. It would need better documentation though to communicate the flexibility of the eval method.

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

No branches or pull requests

2 participants
0