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

2019-08-04 17:50发布

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

3条回答
成全新的幸福
2楼-- · 2019-08-04 18:07

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.

查看更多
Summer. ? 凉城
3楼-- · 2019-08-04 18:13

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.

查看更多
唯我独甜
4楼-- · 2019-08-04 18:33

i think you forgot to declare item.path

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

查看更多
登录 后发表回答