Polymer V.1 how to concatenate some text to iron-l

2019-08-04 17:59发布

问题:

I'm Using iron-ajax with iron-list and for the iron-image i need to concatenate text to the image source that has{{item.path}}

i tried this way

<iron-image style="width:80px; height:80px;" sizing="cover" src="http://mydomain/{{item.path}}.jpg" preload></iron-image>

But i get no image loaded and upon inspecting a list item it doesn't insert the path of the image coming from json data.

src="http://mydomain/{{item.path}}.jpg"

What is the way to concatenate the above

by itself src="{{item.path}}" i see the path when i inspect an item

Thanks

回答1:

String interpolation is not yet supported in Polymer 1.0. You will need to use a computed binding.

For instance:

<dom-module id="your-tag">
  <template>
     <iron-image 
      style="width:80px; height:80px;"
      sizing="cover"
      src$="{{_getImagePath(item.path)}}"
      preload></iron-image>
  </template>
  <script>
    Polymer({
      is: "your-tag",
      _getImagePath: function(url) {
        return 'http://mydomain/' + url + '.jpg';
      }
    });
  </script>
</dom-module>

I have answered a similar question here.



回答2:

i think you forgot to declare item.path

you should Polymer({ item.path: "/set/your/path"});



回答3:

i think this example may solve you problem:

function(myPath) {
    return 'http://mydomain/' + myPath + ".jpg";
}

then you can use in the following way:

src="http://mydomain/{{myPath(item.path)}}"

you may also look here for further investigation and more comprehensive examples.