Beispiel #1
0
	addNotebookTest: function() {
		var doc = {
			// _id: "xxxxx",
			hello: 'world'
		   , n: 5
		   , today: new Date()
		   , nedbIsAwesome: true
		   , notthere: null
		   , notToBeSaved: undefined  // Will not be saved
		   , fruits: [ 'apple', 'orange', 'pear' ]
		   , infos: { name: 'nedb' }
		   };
		console.log("save before")
		db.notebooks.insert(doc, function (err, newDoc) {   // Callback is optional
		  // newDoc is the newly inserted document, including its _id
		  // newDoc has no key called notToBeSaved since its value was undefined
		  // console.log(err);
		  // console.log(newDoc);
		});
	},
Beispiel #2
0
	addNotebook: function(notebookId, title, parentNotebookId, callback) {
		var notebook = {
			Title: title,
			Seq: -1,
			UserId: User.getCurActiveUserId(),
			ParentNotebookId: parentNotebookId,
			LocalIsNew: true,
			IsDirty: true, // 必须, 同步后才为非dirty状态
			// TODO UrlTitle
		}
		if(notebookId) {
			notebook['NotebookId'] = notebookId;
		}
		db.notebooks.insert(notebook, function (err, newDoc) {   // Callback is optional
			if(err) {
				console.log(err);
				callback && callback(false);
			} else {
				callback && callback(newDoc);
			}
		});
	},
Beispiel #3
0
		me.getNotebookIdByServerNotebookId(notebook.ParentNotebookId, function(parentNotebookId) {
			// 如果是第一次添加可能会有问题, 数据库还没有数据, 那么还找不到
			if(parentNotebookId) {
				notebook.ParentNotebookId = parentNotebookId;
			} else {
				// 否则, 就用服务器上的
			}

			notebook.CreatedTime = Common.goNowToDate(notebook.CreatedTime);
			notebook.UpdatedTime = Common.goNowToDate(notebook.UpdatedTime);

			notebook.IsDirty = false;
			notebook.LocalIsNew = false;
			notebook.LocalIsDelete = false;

			db.notebooks.insert(notebook, function (err, newDoc) {   // Callback is optional
				if(err) {
					console.log(err);
					callback && callback(false);
				} else {
					callback && callback(newDoc);
				}
			});
		});