2011-10-05 3 views
0

나는 Drupal 6을 사용하고있다. 나는 dom에 제거 링크를 추가해야한다. 그런 다음 방금 추가 한 링크 제거 요소에 Drupal.attachBehaviors를 사용하고 싶습니다. 나는이 링크에 동작을 첨부하여이 링크의 클릭을 처리 할 수있는 더 많은 자바 스크립트를 작성할 수 있습니다. catch되지 않은 유형의 오류 : 나는Drupal.attachBehaviors : 올바른 인수입니까? (javascript/jquery/Drupal 6)

라인 (10)을 얻을 아래 가지고 내가 행동을 연결하면 메소드를 호출 Cannont 정의되지 않은

$ ("# 편집 필드-제품-REF-제공-0의 '교체' -nid-nid ", context) .val()이 null을 리턴합니다. 내가 아래에있는 Drupal.attachBehaviors 행을 주석 처리하면 오류가 사라지고 team_current는 예상 한 값을 갖습니다.

  1. Drupal.attachBehaviors에 전달하는 내용이 맞습니까?
  2. 왜 내가 Drupal.attachBehaviors 줄이 var team_current 줄에서 오류를 일으키는 지 알 수 있습니까? 자바 스크립트 후에 생성

HTML은 실행 :

<div class="form-item" id="edit-field-product-ref-provider-0-nid-nid-wrapper"> 

    <input type="text" name="field_product_ref_provider[0][nid][nid]" id="edit-field-product-ref-provider-0-nid-nid" size="60" value="bw11 [nid:631]" class="form-text form-autocomplete text noderelationships-nodereference-autocomplete noderelationships[field_product_ref_provider] noderelationships-processed nodeRefUi-processed" autocomplete="OFF"> 

    <div class="noderelationships-nodereference-buttons-wrapper"> 
    <a href="javascript:void(0)" class="noderelationships-nodereference-create-button" title="Create a new support team listing and assign it to this product">Create a new support team listing and assign it to this product</a> 
    <a href="javascript:void(0)" class="noderelationships-nodereference-remove-button" title="Remove support team from this product" style="">Remove support team from this product</a> 
    </div> 

</div> 

자바 스크립트 :

(function ($) { 
    // Store our function as a property of Drupal.behaviors. 
    Drupal.behaviors.tsrNodeRefUi = function (context) { 

    var team_current = $("#edit-field-product-ref-provider-0-nid-nid", context).val().replace(/\s\[nid:\d+\]/, ''); 
    var remove_button = '<a href="javascript:void(0)" class="noderelationships-nodereference-remove-button" title="Remove support team from this product">Remove support team from this product</a>'; 

    //Add Remove link... 
    $(".noderelationships-nodereference-buttons-wrapper").append(remove_button); 

    //Attach Behaviors 
    Drupal.attachBehaviors($(".noderelationships-nodereference-remove-button")); 
    }; 
}(jQuery)); 

답변

1

귀하의 마지막 줄 :

Drupal.attachBehaviors($(".noderelationships-nodereference-remove-button")); 

다음과 같아야합니다.

Drupal.attachBehaviors(remove_button);