Polymer V.1 how to concatenate some text to iron-list item that has json data e.g text{{data.somedata}}text

房东的猫 提交于 2019-12-11 12:11:04

问题


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.



来源:https://stackoverflow.com/questions/31516990/polymer-v-1-how-to-concatenate-some-text-to-iron-list-item-that-has-json-data-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!