json - Custom filter not working in objects -


How to use my custom filter to bind?

Not working:

JSON:

  {"name": "Adrian"}  

HTML:

  & lt; Template Bind = "{{User}}" & gt; & Lt; P & gt; {{Name | Filter}} & lt; / P & gt; & Lt; / Template & gt;  

But it works normally when I use repeat.

Tasks:

JSON:

  [{"Name": "Adrian 1"}, {" Name ":" Adrian 2 "}]  

HTML:

  & lt; Repeat template = "{{user in user}}" & gt; & Lt; P & gt; {{User.name | Filter}} & lt; / P & gt; & Lt; / Template & gt;  

If you defined the filename as a function under the prototype of the element ...

  polymers ('my-element', {filterName: function (value) {return value.toUpperCase ()}});  

When we do

  & lt; Templates & gt; {{User.name | FilterName}} & lt; Templates & gt;  

You have the user ',' user '' and 'filter' callback of your element and its properties.

When you

  & lt; Templates & gt; & Lt; Template Bind = "{{User}}" & gt; {{Name | FilterName}} & lt; / Template & gt; & Lt; / Template & gt;  

Your external template has access to the user and filternames.

But your internal template is now only obliged to view user objects. Your scope is now limited to the user. This is a special case when you use bind.

More info here ...

However, you have options for:

1- Less than ideal -> Callback to a property in your object Add as your model is now responsible for DOM changes waste!

2- If you are reusing the filter, you can convert it to a global expression

  polymerxpress.propotopy.philtername = function (value) { Return value to uppercase (); };  

And now you can use anywhere.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -