我正在使用 Jaydata 和它的 Indexeddbprovider,我在添加场景时遇到了问题。
当有多个添加时,只有第一个有效!
$data.Entity.extend("Person", {
Id: { type: "int", key: true, computed: false },
Task: { type: String, required: true, maxLength: 200 },
DueDate: { type: Date },
Completed: { type: Boolean },
University: { type: "int"},
Degree: { type: "int" }
});
$data.EntityContext.extend("ClientDatabase", {
People: { type: $data.EntitySet, elementType: Person }
});
var db = new ClientDatabase({
provider: 'indexedDb', databaseName: 'ClientDB', version: 1
});
var newEntity = {
Id: 1,
Task: 'task1',
DueDate: new Date(),
Completed: false,
University: 1,
Degree: 1
};
var newEntity2 = {
Id: 4,
Task: 'task4',
DueDate: new Date(),
Completed: false,
University: 4
Degree: 4
};
add(db, newEntity, entity1AddedSuccessfully);
function entity1AddedSuccessfully(){
add(db, newEntity2);
}
function add(db, entity, callback){
db.onReady({
success: function () {
db["_People"].add(entity);
db.saveChanges(function () {
if (callback !== undefined) {
callback(entity);
}
});
}
});
}
问题是在这种情况下,newEntity 只是添加到 ClientDB 并且没有 newEntity2!
任何帮助,将不胜感激。