Polymer V.1 如何将一些文本连接到具有 json 数据的铁列表项目,例如文本{{data.somedata}}文本
Polymer V.1 how to concatenate some text to iron-list item that has json data e.g text{{data.somedata}}text
我将 iron-ajax 与 iron-list 一起使用,对于 iron-image,我需要将文本连接到具有 {{item.path}}
的图像源
我这样试过
<iron-image style="width:80px; height:80px;" sizing="cover" src="http://mydomain/{{item.path}}.jpg" preload></iron-image>
但是我没有加载图像,并且在检查列表项时它没有插入来自 json 数据的图像路径。
src="http://mydomain/{{item.path}}.jpg"
上面的拼接方法是什么
自己src="{{item.path}}"
我在检查项目时看到了路径
谢谢
我想你忘了申报 item.path
你应该
聚合物({ item.path: "/set/your/path"});
Polymer 1.0 尚不支持字符串插值。您将需要使用 computed binding.
例如:
<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>
我回答过类似的问题。
我认为这个例子可以解决你的问题:
function(myPath) {
return 'http://mydomain/' + myPath + ".jpg";
}
那么您可以通过以下方式使用:
src="http://mydomain/{{myPath(item.path)}}"
您还可以查看 here 以进一步调查和更全面的示例。
我将 iron-ajax 与 iron-list 一起使用,对于 iron-image,我需要将文本连接到具有 {{item.path}}
我这样试过
<iron-image style="width:80px; height:80px;" sizing="cover" src="http://mydomain/{{item.path}}.jpg" preload></iron-image>
但是我没有加载图像,并且在检查列表项时它没有插入来自 json 数据的图像路径。
src="http://mydomain/{{item.path}}.jpg"
上面的拼接方法是什么
自己src="{{item.path}}"
我在检查项目时看到了路径
谢谢
我想你忘了申报 item.path
你应该 聚合物({ item.path: "/set/your/path"});
Polymer 1.0 尚不支持字符串插值。您将需要使用 computed binding.
例如:
<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>
我回答过类似的问题
我认为这个例子可以解决你的问题:
function(myPath) {
return 'http://mydomain/' + myPath + ".jpg";
}
那么您可以通过以下方式使用:
src="http://mydomain/{{myPath(item.path)}}"
您还可以查看 here 以进一步调查和更全面的示例。