2014-09-17 1 views
0

내 앱에서 /home -by home 모델의 데이터를 가져옵니다. Model에는 defaults 객체가 포함됩니다. 그러나 데이터를 가져 오는 동안 모델에서 기본 개체를 볼 수 없습니다.모델에서 가져 오기가 기본값을 제공하지 않습니다.

socialApp.homeView = Backbone.Marionette.ItemView.extend({ 
      tagName:'div', 
      initialize:function() { 
       var that = this; 
       this.model.fetch().done(function(data){ 
        that.render(data) // i am fetching here 
       }); 
      }, 

      render: function (data) { 
       console.log(data) //there is no defaults object here... 
       this.$el.html(homeTemp(data)); 
      } 
     }); 

여기에 어떤 문제가 :

여기
define(['backbone'], function(Backbone){ 
    "use strict"; 
    socialApp = window.socialApp || {}; 

    socialApp.homeModel = Backbone.Model.extend({ 
     url: "/home", 
     defaults:{ 
      "category":"Level-1" 
     } 
    }); 

    return socialApp.homeModel; 
}); 

내 view.js입니다 : 여기

내 모델? Nodejs을 서버로 사용하고 있습니다. adavnce에서

{ 
__v: 0 
_id: "5416ce23fc0c41ec0f03f672" 
email: "[email protected]" 
firstName: "Mohamed" 
lastName: "Afzil" 
password: "afzil" 
username: "afzil" 
} 

감사 : 여기

내가 무엇입니까 무엇 콘솔입니다.

+1

콘솔 로그 this.model 및 – StateLess

+1

가'this.model''socialApp.homeModel'의'socialApp.homeView' 인스턴스에 확인 :

이로 초기화 기능을 수정하세요? 게다가 itemView에'render'를 구현할 필요가 없으며'tagName : 'div'''를 기본값으로 정의 할 필요가 없습니다. 그것으로 충분하다 -'initialize : function() {this.model.on ('fetch', this.render, this); this.model.fetch()}' – Evgeniy

+0

@Evgeniy'플러스 itemView'에서 render를 구현할 필요가 없습니다 - 당신이'render' 메소드를 제거하길 원합니까? json을 템플릿에 전달하는 방법은 무엇입니까? – 3gwebtrain

답변

1

'done'콜백에서 볼 수 있듯이 모델이 아니라 결과 만 가져올 수 있습니다.

initialize: function() { 
    var that = this; 
    this.model.fetch({ 
     success: function(model){ 
      that.render(model.toJSON()); 
     } 
    }); 
}