2017-01-03 91 views
0

Symfony的形式收集我創建形式發票,並希望創建加載形式添加客戶,閱讀烹飪書,並有埃羅動態加載實體關係

Uncaught ReferenceError: $ is not defined 
at new:32 

爲什麼$('<a href="#" class="add_customer_link">Add a customer</a>')返回錯誤?

這個模板

{{ form_start(form) }} 

{{ form_row(form.companyReference) }} 
{{ form_row(form.customerReference) }} 

<h3>Customer</h3> 
<ul class="tags" data-prototype="{{ form_widget(form.customer.vars.prototype)|e('html_attr') }}"> 
    {% for customer in form.customer %} 
     <li>{{ form_row(customer.name) }}</li> 
    {% endfor %} 
    <a href="#" class="add_customer_link">Add a tag</a> 
</ul> 

{{ form_end(form) }} 



<script> 
    var $collectionHolder; 
    var $addTagLink = $('<a href="#" class="add_customer_link">Add a customer</a>'); 
    var $newLinkLi = $('<li></li>').append($addTagLink); 

    jQuery(document).ready(function() { 
     $collectionHolder = $('ul.tags'); 
     $collectionHolder.append($newLinkLi); 
     $collectionHolder.data('index', $collectionHolder.find(':input').length); 

     $addTagLink.on('click', function(e) { 
      e.preventDefault(); 
      addTagForm($collectionHolder, $newLinkLi); 
     }); 
    }); 
</script> 

什麼我'做錯了,怎麼做吧?

+1

你'包括插件jquery'? –

回答

0

使用以下

<script> 
var $collectionHolder; 
var $addTagLink; 
var $newLinkLi; 

jQuery(document).ready(function() { 
    $addTagLink = $('<a href="#" class="add_customer_link">Add a customer</a>'); 
    $newLinkLi = $('<li></li>').append($addTagLink); 
    $collectionHolder = $('ul.tags'); 
    $collectionHolder.append($newLinkLi); 
    $collectionHolder.data('index', $collectionHolder.find(':input').length); 

    $addTagLink.on('click', function(e) { 
     e.preventDefault(); 
     addTagForm($collectionHolder, $newLinkLi); 
    }); 
});