2017-11-12 7 views
2

私は基本的なレベルで問題があります.Javascriptファイルでボディの代わりにテンプレート名を使用すると流星で動作しません。ここ体の代わりにテンプレート名を使用すると流星の場合

は私のhtmlコードです:

<head> 
    <title>simple</title> 
</head> 

<body> 
    <ul> 

    {{#each player}} 

     <li> {{text}}</li> 


    {{/each}} 

    </ul> 
</body> 

<template name="shahin"> 

    {{player}} 

</template> 

JavaScriptコード:私はこのコードを実行する場合さて、それは何も表示されません

Template.shahin.helpers({ 
     player: [ 
     { text: "This is paragraph 1..." }, 
     { text: "This is paragraph 2..." }, 
     { text: "This is paragraph 3..." }, 
     { text: "This is paragraph 4..." }, 
     { text: "This is paragraph 5..." } 
     ] 
    }); 

。しかし、私はこれで私のTamplateの名前に変わります

Template.body.helpers 

このコードは動作しています。誰かがなぜこのような理由を説明できますか?なぜこれが機能していないのか教えてください:

Template.shahin.helpers 

答えて

2

あなたの体のどこにでもテンプレートを呼び出さないので、これはうまくいかないのです。

これを試してみてください:

 <head> 
    <title>simple</title> 
</head> 

<body> 
    {{> shahin}} <!-- this is where the contents of template="shahin" will render. If you don't call this, "shahin" will never get displayed --> 
</body> 

<template name="shahin"> 

    <ul> 

    {{#each player}} 

     <li> {{text}}</li> 


    {{/each}} 

    </ul> 

</template> 
+0

はどうもありがとうございました。もう一つ。プロパティ値とプロパティ値を表示する方法を教えてください。上記の場合、私はちょうどプロパティとして 'テキスト'を持っています。異なる値とともに異なるプロパティを持つ場合はどうすればいいですか?どのようにプロパティを表示しますか:身体の値ですか? – Kazi

+0

それでは、そのプロパティを呼び出す必要があります。配列のオブジェクトが '' {{text: "abc"、 "name": "spiderman"、 "contact":121}、{text: "def"、 "name": "doge "、" contact ":132}]' ''それを呼び出すと: '' {{#each player}}

  • {{text}}、{{name}}、{{contact}}
  • '' ' – blueren

    関連する問題