백본 모델, 보드, 정확한 출력을 얻을 수 없습니다backbonejs model.toJSON() backbone.iobind
define([
'underscore',
'backbone',
'collections/lists',
'iobind',
'iosync'
], function(_, Backbone, Lists,ioBind,ioSync) {
var BoardModel = Backbone.Model.extend({
urlRoot: 'board',
noIoBind: false,
socket: io.connect(''),
idAttribute: '_id',
defaults: {
title: 'One Thousand and One Nights'
},
initialize: function() {
this.id = 1;
this.lists = new Lists;
this.socket.emit('joinBoard',this.id);
_.bindAll(this, 'getBoard');
this.ioBind('initBoard', this.getBoard, this);
},
getBoard: function(data){
this.set(data.data.board[0]);
}
});
return BoardModel;
});
백본보기 : boardView :
var IndexView = Backbone.View.extend({
// Instead of generating a new element, bind to the existing elements in the HTML.
el: '#board',
// Board template html
template: Mustache.render(Template.board),
events: {
},
initialize: function() {
//Init Data
this.model = new Board();
// var lists = {
// lists: [
// {name: "To Do",
// cards:[
// {name: "Art work for A."},
// {name: "B Prototype."},
// {name: "C prototype."}
// ]
// },
// {name: "Doing",
// cards: [
// {name: "Art work for A."}
// ]
// },
// {name: "Done"}
// ]
// }
// var partial = {card: Template.card_in_list};
// var listHtml = Mustache.render(Template.list,lists,partial);
// template = $(this.template).find('.list-area').append(listHtml);
},
render: function() {
console.log(this.model);
console.log(this.model.toJSON());
var partial = {card: Template.card_in_list};
var listHtml = Mustache.render(Template.list,this.model,partial);
template = $(this.template).find('.list-area').append(listHtml);
this.$el.html(template);
}
});
보기 기능에서 : 기능을 렌더링 console.log는 다른 결과를 얻습니다. 을 console.log (this.model는) 올바른 개체 결과를 얻을 수 있습니다
child
_callbacks: Object
_changing: false
_escapedAttributes: Object
_ioEvents: Object
_pending: Object
_previousAttributes: Object
_silent: Object
attributes: Object
__v: 0
_id: "50b750a7795f285d4e000014"
created: "2012-11-29T12:10:15.269Z"
description: "simple is better, but not simpler"
dueDate: "2012-11-29T12:10:15.269Z"
lists: Array[6]
status: true
title: "test board unique"
__proto__: Object
changed: Object
cid: "c1"
getBoard: function() { [native code] }
id: "50b750a7795f285d4e000014"
lists: child
__proto__: ctor
하지만 this.model.toJSON()는 모델의 기본 값을 얻을 :
Object
title: "One Thousand and One Nights"
__proto__: Object
그것은 나를 혼란. 누구도 같은 모델이 다른 결과를 얻는 이유를 알고 있습니다.
안녕하세요! https://github.com/logicalparadox/backbone.iobind/issues/26 "Uncaught ReferenceError : module is not defined"문제를 어떻게 해결할 수 있었습니까? 건배. – Puigcerber