-
Notifications
You must be signed in to change notification settings - Fork 396
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
is it possible to get component attributes? #2059
Comments
All data attributes passed to components are set at the root level, so you can use |
@Madgvox <panel x="1" y="2" z="3">
<!-- child compoennt -->
<child ref="item" m="1" ... />
<child ref="chart" n="2" ... />
</panel> now the data object in {
x: 1,
y: 2,
z: 3,
item: {
m: 1
// any other attributes
},
chart: {
n:2
// any other attributes
}
} so the |
There's 2 ways to do it: In one end, you can use the <panel a="{{ x }}" b="{{ y }}" c="{{ z }}" stuff="{{ item }}" graph="{{ chart }}">
<child ref="item" m="{{ stuff.m }}" ... />
<child ref="chart" n="{{ graph.n }}" ... />
<!-- also access x as "a", y as "b" and z as "c" -->
</panel> Inside <div class="panel">
<header>...</header>
<div>{{>content}}</div>
<footer>...</footer>
</div> The other way is to use <panel>
<child ref="item" m="{{ item.m }}" ... />
<child ref="chart" n="{{ chart.n }}" ... />
<!-- can also access x, y and z directly -->
</panel> Inside <div class="panel">
<header>...</header>
<div>{{yield}}</div>
<footer>...</footer>
</div> |
@simongfxu perhaps what you are asking is how to pass a set of values. If so, a keypath expression may be what you're looking for: <panel x="1" y="2" z="3">
<!-- child compoennt -->
<child ref="item" attributes="this['item']" ... />
<child ref="chart" attributes="this['chart']" ... />
</panel> |
@fskreuz @martypdx My really intention is to let the attributes to be more flat. Why i did in this way becasue we can not set complicated attributes directly. Just consider the var tabs = [
{
label: 'tab1',
value: 'value1',
ajaxUrl: '...',
ajaxParams: {some other object},
formatters:[some array]
},
....
] Attribute like <pane tabs="{{tabs}}" /> But I do not think this is a good way:
so if wen can set attributes in this way: <panel
tabs.0.label="tab1" tabs.0.value="val1"
tabs.0.ajaxUrl="/abc" ... /> would it be better? |
@simongfxu
I think I now get it. I think you mean you want to hard-code the values in the template instead of putting it in JS. And the No problem, but you still need a second component ( <!-- General look -->
<panel>
<tab label="label1" value="value1" ajaxUrl="ajaxUrl1" />
<tab label="label2" value="value2" ajaxUrl="ajaxUrl2" />
<tab label="label3" value="value3" ajaxUrl="ajaxUrl3" />
</panel>
<!-- In panel component -->
<div class="panel">{{ yield }}</div>
<!-- In tabs component -->
<div class="tab">
<div class="label">{{ label }}</label>
<div class="content">{{ value }}</label>
</div> Anyways, regarding dotted attribute support, there's an ongoing thread about its support #2060. Feel free to jump in. I also suggest you take a look at the component spec for authors. There's a way to write a component with all HTML, CSS and JS in one file. That way, you don't have to resort to hard-code trickery while still keeping separation of responsibilities. |
@fskreuz |
Ha, I actually opened that issue because of the experimentation I did with your issue! 😄 |
i have not seen it in any official document, so may be it is a feature request?
widget.js
this options in
widget.js
only get x and y without Ractive.defaults.data or any other external settingsThe text was updated successfully, but these errors were encountered: