Json 将mongoose模型引导到BackboneJS
我已经定义了以下嵌入式docs Mongoose模型Json 将mongoose模型引导到BackboneJS,json,backbone.js,mongoose,express,Json,Backbone.js,Mongoose,Express,我已经定义了以下嵌入式docs Mongoose模型 var mongoose = require("mongoose"); module.exports = function(mongoose) { var Schema = mongoose.Schema, chapters, articles; Articles = new Schema({ identity: Number,
var mongoose = require("mongoose");
module.exports = function(mongoose) {
var Schema = mongoose.Schema,
chapters, articles;
Articles = new Schema({
identity: Number,
order: Number,
quick_title: String,
full_title: String,
last_edited: Number,
contributor: [String],
content: String,
video_link: String,
presentation_link: String,
question_id: [Number],
show_in_chapter: Boolean,
summary_text: String,
summary_image: String
});
chapters = new Schema({
order: Number,
title: String,
articles: [Articles]
});
return mongoose.model('chapters', chapters);
}
通过.find获取整个模型数据库后,我目前正尝试使用作者推荐的方法(使用EJS模板引擎)将其引导到backboneJS模型中:
当使用.at方法时,在(0)处也只有一个模型。有什么想法吗?如果不在服务器上使用JSON.stringify,请尝试使用Unescaped缓冲
chapters = new Chapters(<%- JSON.stringify(chapters) %>);
chapters=新章节();
要在更新后回答您的问题,如果您在服务器端使用JSON.stringify,下面的内容对我有用
var Chapter = Backbone.Model.extend({});
var Chapters = Backbone.Collection.extend({
model: Chapter
});
var collection = new Chapters(<%-names%>);
console.log(collection.toJSON());
var Chapter=Backbone.Model.extend({});
var Chapters=Backbone.Collection.extend({
型号:第章
});
var集合=新章节();
log(collection.toJSON());
出现了相同的错误。如果我用引号括起来,那么它会在第一行出现一个意外的非法错误:chapters=newchapters(JSON.stringify)(“Chapter 1-Something,{summary_image:'',在将其发送到模板之前使用stringify使其工作,然后将其放在括号内。仍然无法将其正确输出到主干模型。抱歉,这是我的想法,但完全错了,解决方案是:chapters=new chapters();
chapters = new Chapters(<%- JSON.stringify(chapters) %>);
var Chapter = Backbone.Model.extend({});
var Chapters = Backbone.Collection.extend({
model: Chapter
});
var collection = new Chapters(<%-names%>);
console.log(collection.toJSON());