2017-10-24 5 views
0

ここでは、私はボタンがクリックされるたびにレンダリングするテンプレートです:jQueryの - すべてのloadTemplateの入力の名前を変更する()

<script id="hidden-template" type="text/html"> 
<div id="order-container"> 
    <div class="form-group "> 
     <input class="form-control name" placeholder="Name" type="text"> 
    </div> 
    <div class="form-group "> 
     <ul class="food" style="list-style-type: none; display:inline-block;"> 
      <li><label><input value="burger" type="radio" class="burger" data-name="food">Burger</label></li> 
      <li><label><input value="chicken" type="radio" class="chicken" name="food">Chicken</label></li> 
      <li><label><input value="falafel" type="radio" class="falafel" name="food">Falafel</label></li> 
      <li><label><input value="fries" type="radio" class="fries" name="food">Fries</label></li> 
     </ul> 
     <ul class="veggies" style="list-style-type: none; display:inline-block;"> 
      <li><label><input type="checkbox" class="lettuce" name="veggie">Lettuce</label></li> 
      <li><label><input type="checkbox" class="tomato" name="veggie">Tomato</label></li> 
      <li><label><input type="checkbox" class="cucumber" name="veggie">Cucumber</label></li> 
      <li><label><input type="checkbox" class="onion" name="veggie">Onion</label></li> 
     </ul> 
     <ul class="sauces" style="list-style-type: none; display:inline-block;"> 
      <li><label><input type="radio" class="XSpice" name="sauce">Extra Spicy</label></li> 
      <li><label><input type="radio" class="spice" name="sauce">Spicy</label></li> 
      <li><label><input type="radio" class="mild" name="sauce">Mild</label></li> 
      <li><label><input type="radio" class="noSpice" name="sauce">No Spice</label></li> 
     </ul> 
    </div> 
</div> 

そして、最初の最初のリスト項目にリストには、新しいテンプレートを読み込んだときに別の名前が付いているため、そのテンプレートの他のすべての入力に影響しないように、各テンプレートのカスタム名を追加しようとしています。

$("#app").loadTemplate($("#hidden-template"), { 
    food: "TESTING" 
}) 

が、私は入力の名前をCONSOLE.LOGとき、それはundefinedを返します:私はそれをレンダリングしていますのはここ

です。データ名のようなものはありませんか?私はそれがJQueryのプラグインであると思うので、良い文書を見つけることができないようです。テンプレートをロードするたびに入力の名前を変更するにはどうすればよいですか?それとも私がこれをやることができるより良い方法がありますか?

答えて

0

これはどうでしょうか?

$("li").first().attr('data-name') = "TESTING"; 
+0

私の文章中の悪い言葉遣いのため申し訳ありませんが、私はちょうど質問を簡単にするために最初の1に別の名前を適用したいが、私のアプリで私は特別な名前を持つようにしたいことを言おうとしました各入力セット。 (例えばfood1、food2、veggie1、veggie2)無線入力が他のテンプレート無線と干渉しないようにする – user8813240

+0

データは最終的にどのように提出されますか? HTMLフォームの提出またはJavascript? 提案:後で編集するのではなく、get goとは異なるリストを生成することをお勧めします。 –

+0

JavaScript経由です。違うリストを生成するとどういう意味ですか?私は今何をしているのではないですか?それぞれに少しの変更を加えて新しいテンプレートを生成する。 – user8813240

関連する問題