2014-02-07 92 views
0

我的問題是我的smarty腳本在使用after()jquery將它追加到DOM時不會工作,當用戶嘗試添加新項目並在最後一個表格後面插入時使用此腳本行。將Smarty腳本添加到DOM中

在PHP

var smartyFetchItem = '{section name=cnt loop=$ItemsVal}<option value="{$ItemsVal[cnt].itemname}" >{$ItemsVal[cnt].itemname}</option>{/section}'; 

    $('tbody.tbodyruler tr:last').after('<tr><td><input type="hidden" id="ds" name="itemname[]"><select class="itemanm"><option value="others">If Others - Please fill up add info</option>'+smartyFetchItem+'</select></td><td><input type="text" name="addinfo[]" id="addinfo[]" value="none"></td><td><input class="spinner" name="quantity[]" id="quantity[]" value="1"></td><td></td><td><input type="hidden" name="unitprice[]" id="unitprice[]" class="unitprice"></td><td></td><td><input type="hidden" name="total[]" id="total[]" class="subtot" readonly></td></tr>'); 

在TPL

<tbody class="tbodyruler"> 

    {section name=count loop=$counter} 
     <tr> 

     <td><input type="hidden" id="ds" name="itemname[]"> 
     <select class="itemanm"> 
      <option value="others">If Others - Please fill up add info</option> 
      {section name=cnt loop=$ItemsVal} 
      <option value="{$ItemsVal[cnt].itemname}" >{$ItemsVal[cnt].itemname}</option> 
      {/section} 
      </select> 
     </td> 
     <td><input type="text" name="addinfo[]" id="addinfo[]" value="none"></td> 
     <td><input class="spinner" name="quantity[]" id="quantity[]" value="1"></td> 
     <td></td> 
     <td><input type="hidden" name="unitprice[]" id="unitprice[]" class="unitprice"></td> 
     <td></td> 
     <td><input type="hidden" name="total[]" id="total[]" class="subtot" readonly></td> 

     </tr> 

     {/section} 

回答

0

嘗試這個

var smartyFetchItem = '';  
    {section name=cnt loop=$ItemsVal} {literal} 
     smartyFetchItem = smartyFetchItem + '<option value="{$ItemsVal[cnt].itemname}" >{$ItemsVal[cnt].itemname}</option>'; 
    {/section} 

    $('tbody.tbodyruler tr:last').after('<tr><td><input type="hidden" id="ds" name="itemname[]"><select class="itemanm"><option value="others">If Others - Please fill up add info</option>'+smartyFetchItem+'</select></td><td><input type="text" name="addinfo[]" id="addinfo[]" value="none"></td><td><input class="spinner" name="quantity[]" id="quantity[]" value="1"></td><td></td><td><input type="hidden" name="unitprice[]" id="unitprice[]" class="unitprice"></td><td></td><td><input type="hidden" name="total[]" id="total[]" class="subtot" readonly></td></tr>');