我有一個dom-repeat,我想根據函數使用src插入圖像。這次在函數中使用索引不能解決問題,現在我被卡住了。聚合物的版本是1.8.0 我試過至今不同的方式,最後一個是:錯誤「Uncaught TypeError:無法設置屬性'src'null」在dom-repeat中
<template is="dom-repeat" items="{{top.top}}" as="item">
<img id="testid" src="{{imgurl}}">
</template>
<script>
Polymer({
is: 'test',
ready: function() {
// Polymer.dom(this).querySelector('testid').src = this.imgurl;
this.$.testid.src = this.imgurl;
} ,
properties: {
top: {
type: Array,
value: function() { return []; }
},
imgurl: {
type: String,
notify: true,
reflectToAttribute: true,
computed: 'changeimg(score, oldscore)'
}
},
changeimg: function(score, oldscore) {
if(score>oldscore){url = "images/reddown.png";}
else if(score<oldscore){url ="images/greenup.png";}
else {url = "images/blueorizontal.png";}
return url;
},
....
});
</script>
始終的結果是一樣的... 任何IDEEA?謝謝
您是否嘗試過使用src $而不是src? – Ofisora
您的意思是:?那麼,是的,我試圖... – vlucian
你能澄清你的頂級數組的內容是什麼樣子,你想要完成什麼。你的代碼有幾個問題,我認爲不會達到你真正想要的。 – Scarygami