ractivejs

ractive-1.0.0-build9 parser error with interpolation within attribute


I'm in the process of upgrading to rev 1.0.0 build9. (Code was passing all tests with rev 0.7.3.)

In the template I have an element:

  <div on-click='complaint_{{id}}_edit_cancel()'/>

The mustache interpolation within that attribute is causing a parser error. I realize that there may be other ways to pass this variable to the event handler, but how should such interpolation be handled so as not to trigger a parser error?


Solution

  • Not sure if this was officially supported or if this was a side-effect of attribute parsing (which would make it a bug). As far as I know, Ractive only supports either a string or a JS expression as values of the on-* directive. Also, a function per id is a strange setup.

    Anyways, expressions have full, unmustached access to data in the context. You can pass i as an argument of either a method call or a proxy event.

    // passes id as argument to a method
    <div on-click="complaint_edit_cancel(id)"/>
    
    // passes id as argument to an event, handled by ractive.on
    <div on-click="['complaint_edit_cancel', id]"/>