2012-05-16 5 views
1

이벤트를 뷰에서 실행하려고 시도했지만 트리거되지 않는 것 같습니다. 이보기는 다른보기에서 실행되므로 이벤트가 제대로 설정되지 않았는지 확실하지 않습니다. 그 대신이 시도의 주위에 당신의 DOM 표현이 추가 포장 요소를 갖는 당신에게 문제를 일으키는 경우백본 이벤트가 실행되지 않습니다.

var ListRow = Backbone.View.extend(
{ 
    events: 
    { 
     'click .button.delete': 'destroy' 
    }, 

    initialize: function() 
    { 
     _.bindAll(this, 'render', 'remove'); 
    }, 

    render: function() 
    { 
     this.el = _.template($('#tpl-sTableList_' + key + 'Row').html()); 

     return this; 
    }, 


    destroy: function() 
    { 
     console.log('remove') 
    } 
}); 
+0

여기에 this.el = _.template ($ ('# tpl-sTableList_'+ 키 + '행') .html());'** 키 **는 어디서 왔습니까 – Deeptechtons

답변

3

당신은 당신이 대신 수행 할 작업을 당신의 this.el

render: function() 
{ 
    var tpl = _.template($('#tpl-sTableList_' + key + 'Row').html()); 
    this.$el.empty().html(tpl); 
    // or if you prefer the old way 
    // $(this.el).empty().html(tpl); 
    return this; 
}, 

됩니다 덮어 쓰기하고 있습니다 :

render: function() 
{ 
    var tpl = _.template($('#tpl-sTableList_' + key + 'Row').html()); 
    this.setElement(tpl, true); // this is a Backbone helper 
    return this; 
}, 
+1

그리고 [ setElement'] (http : //documentcloud.github. co.kr/backbone/# View-setElement)은 특히 this.el을 대체하고 모든 내부 (예 : [this. $ el'] (http : //documentcloud.github) .com/백본/#보기 - $ el) 및 [이벤트] (http://documentcloud.github.com/backbone/#View-delegateEvents))가 올바르게 재설정됩니다. –

+0

좋아요, 첫 번째 부분은 나에게 의미가 있습니다. 요소는 문자열이 아니기 때문에 붙지 않았습니다. 그 시점의 요소가 아닙니다. 어느 날 두 번째 지점으로 데려다 줄, 일반적으로 괜찮을 것이라고 내 서식 파일을 래핑하는 div 있지만 테이블에 tr 추가하는 것이기 때문에 깨고 있어요. 이 setElement는'setElement' 라인 바로 다음에'console.log (this.el)'을 실행하면 "Node가 계층 구조의 지정된 위치에 삽입 될 수 없습니다"오류를 주며,'Document' 목적? – Rob

+0

이제 tpl()에 대괄호가 없어졌습니다. 감사합니다! – Rob

관련 문제