我尝试按照Build a Collaborative Data Model中描述的步骤操作,最后得到以下代码:
function onLoad(doc){
var Book = function(){};
var model = doc.getModel();
gapi.drive.realtime.custom.registerType(Book, 'Book');
Book.prototype.title = gapi.drive.realtime.custom.collaborativeField('title');
Book.prototype.author = gapi.drive.realtime.custom.collaborativeField('author');
Book.prototype.isbn = gapi.drive.realtime.custom.collaborativeField('isbn');
Book.prototype.isCheckedOut = gapi.drive.realtime.custom.collaborativeField('isCheckedOut');
Book.prototype.reviews = gapi.drive.realtime.custom.collaborativeField('reviews');
var book = model.create('Book');
model.getRoot().set('book', book);
book.addEventListener(gapi.drive.realtime.EventType.OBJECT_CHANGED, function(e){console.log(e);});
book.title = 'Moby Dick';
book.author = 'Melville, Herman';
book.isbn = '978-1470178192';
book.isCheckedOut = false;
}
不幸的是,执行此操作时,执行var book = model.create('Book');
时出现以下错误:
未捕获java.lang.IllegalArgumentException:未知类型名称Book
Drive Realtime API错误:invalid_compound_operation:在同步块结束时打开复合操作 - 您是否忘记调用endCompoundOperation()?
我想念什么?
答案 0 :(得分:2)
您需要在加载文档之前注册自定义类型。
这里有三个不同的部分:
将你的功能分成这三部分,它应该可以工作。