問題は、if
とのPhoto
間#=
に囲まれていることです#
が、if
はすでに に囲まれているため、その#
必要はありません。
次はそれPhoto
が要素の一部であるTerritories
ため、(私が思うに)だけでなくもチェックTerritories[i].Photo
する必要があります。null
Photo
テンプレートは次のようにする必要があります。
<script type="text/x-kendo-template" id="storeTerritory">
<div class="tooltipcontent">
#for(var i = 0; i < Territories.length; i++){#
#if (Territories[i].Photo != 'null' && Territories[i].Photo != '') {#
<img src="#=Territories[i].Photo#" alt="" />
#} else{#
<img src="https://cdn4.iconfinder.com/data/icons/website-kit-2/600/547756-Cross-128.png" alt="" />
#}#
#}#
</div>
</script>
ここで確認してください:http://jsbin.com/iJunOsa/32/
EDITコメントに続いて、Territories
フィールドに複数の要素があり、それぞれが異なるを使用する必要Photo
があるため、表示する写真を識別するという追加の問題が1つあります。
簡単な方法は、テンプレートに写真に関する情報を追加することです。このテンプレートは、表示されたときにどれを表示するかを正確に認識Description
できるテキストを生成します。Tooltip
Photo
つまり、生成に使用するテンプレートを次のように変更しますDescription
。
<script type="text/x-kendo-template" id="territoriesTemplate">
#for(var i = 0; i < Territories.length; i++){#
<a class="hasTooltip" data-photo="#= Territories[i].Photo #">#:Territories[i].TerritoryDescription#</a> <button class="info-btn">Info</button>
#}#
</script>
data-photo
値が写真へのパスである要素を追加した場所で、ツールチップに表示されます(つまりdata-photo="#= Territories[i].Photo #"
、アンカーに追加しa
ます)。
次に、ツールチップを生成するコードは次のように単純になります。
content: function (e) {
// Get the template
var template = kendo.template($("#storeTerritory").html());
// Retrieve the photo from data and send it as argument to the template
return template({ photo : $(e.target).data("photo")});
}
最後に、テンプレートの新しい定義も非常に単純です。
<script type="text/x-kendo-template" id="storeTerritory">
<div class="tooltipcontent">
#if (photo) {#
<img src="#=photo#" alt="" />
#} else{#
<img src="https://cdn4.iconfinder.com/data/icons/website-kit-2/600/547756-Cross-128.png" alt="" />
#}#
</div>
</script>
が定義されているかどうかを単純にチェックし、photo
定義されている場合はそれを使用し、そうでない場合はデフォルト値を使用します。
ここで実際に見てください:http://jsbin.com/iJunOsa/40/