Skip to content

Support converters with template binding #87

Description

@wglasshusain

I want to use a function to pull the last item of an array (usually of time). Right now I am doing

 <script>
        function current(item) {
            if (!item || item.constructor != Array) {
                return item;
            } else {
                return (item.length == 0) ? null : item[item.length - 1];
            }
        }
 </script>

<p data-f-bind="Time,Inventory"> The current time is <%= current(Time) %> and inventory is <%= current(Inventory) %>
<p>

I thought I could make this into a converter but it didn't work

<script>
    Flow.dom.attributes.register('current', function (item) {
           if (!item || item.constructor != Array) {
                return item;
            } else {
                return (item.length == 0) ? null : item[item.length - 1];
            }
        });
</script>


<p data-f-bind="Time,Inventory | current"> 
     The current time is <%= Time %> and inventory is <%= Inventory %>
</p>

I get an error "converter-manager.js:159. Uncaught Error: Could not find converter for current"

Can we support converters with the example above? I think it'd be ok to have the converter applied to all variables in the list.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions