2013-06-04 2 views
0

변수를 한 뷰에서 다른 뷰로 전달하려고하면 두 번째 뷰에서 항목이 정의되지 않습니다.Backbone.js - 값이 뷰에서 다른 뷰로 전달되지 않습니다.

이 내 게시물이

Stream.Views.PostEntry = Backbone.View.extend({ 

    template: JST['streams/post'], 

    render: function(){ 
    console.log(entry); // Error: 'entry is not defined' 
    this.$el.html(this.template({post: entry})); 
    return this; 
    } 
}); 
+0

너무 짧습니다. –

답변

1

백본 (보기 # 자세한 것은 초기화 볼이의 속성에 할당하여 생성자에 어떤 인자를 처리하는 내 게시물 항목이다

append_post: function(post){   
    view = new Stream.Views.PostEntry({entry: post}); 
    $("#stream-bank").append(view.render().el); 
} 

보기입니다), 나머지는 이것으로 들어갑니다. - MU 당신은 실수 (I 희망)`VAR view` 내부`append_post` 말을하지 않음으로써 전역 변수를 만든

render: function(){ 
    console.log(this.options.entry); // 
    this.$el.html(this.template({post: this.options.entry})); 
    return this; 
} 
+2

'this.options.entry'를 의미하지 않습니까? –

+0

this.entry 할 때 게시 정의되지 않았습니다. 그러나 이것. 선택. 엔트리가 작동합니다! 감사! –

+1

@Srikanth : 백본은 생성자에 대한 일부 인수를 'this'속성에 할당하여 처리합니다 (자세한 내용은 [View # initialize'] (http://backbonejs.org/#View-constructor) 참조), 나머지는 이동합니다 'this.options'에 추가하십시오. –

관련 문제