Search code examples
javascriptractivejs

Forward data to component in Ractive.js


Let's say I want to dynamically generate a collection of Ractive components from an array that specifies the data that should be passed to each instance:

var items = [
    { data: { foo: "bar1" } },
    { data: { foo: "bar2" } }
];

Is there any way to forward that data to component so that it sees it as it's data - not as a property called "data".

{{#each items}}
    <Component __data__="{{data}}" />
{{/each}}

The reason for this is that I want to be able to easily reuse Components for both dynamic list and without dyanmic lists:

<Component foo="bar3" />

Solution

  • This PR would do exactly that via:

    <Component this='{{data}}'/>