ractivejs / ractive

Next-generation DOM manipulation
http://ractive.js.org
MIT License
5.94k stars 396 forks source link

External template on-click event #3318

Closed TanvirAlam closed 5 years ago

TanvirAlam commented 5 years ago

Description:

I am generating templates with raw data:

<dl>
            {{#each propertyTypeDTOList}}
            <dt>
                {{propertyTypeName}}
            </dt>
                {{#each propertyList}}
                <dd>
                    {{value}}
                </dd>
                {{/each}}
            {{/each}}
        </dl>

The {{value}} has lot of a-tags eg: (First link E <a class="tree-node-pointer" title="Link to E" target="">Link to E</a>) and I parse using regex to get the <a></a> and dynamically adding:

(First link E <a class="tree-node-pointer" on-click="['replaceLink','f2699811-da98-4abb-98f8-d7a30922d894','E']" title="Link to E" target="">Link to E</a>)

Everything is workin g just fine, however if I escape with {{{ value }}}

The on-click event is there but its not working.

Please help if you can

Created simple Jfiddle

https://jsfiddle.net/tanvir_alam_shawn/2Ltuvmj9/

Versions affected:

Ractive.js 1.2.4

evs-chris commented 5 years ago

What you're doing is trying to have templates as strings parsed and rendered inline, which is possible, but not using an interpolator. What you'll want to do is use them from a partial {{>{ template: value }}}, which will parse them as a template, giving you access to ractive features, and then render the resulting template. https://jsfiddle.net/f0pdu5ow/

TanvirAlam commented 5 years ago

@evs-chris Thank you that worked, I did not know.