【发布时间】:2015-01-19 09:40:46
【问题描述】:
美好的一天,我正在使用 ExtJS4 构建一个 Web 应用程序,我在其中创建了多个模型,然后将它们添加到商店,然后同步商店。但是,在调用store.sync() 时,我看到一个空白的数据库条目。
我的代码是这样的:
this.mon(uploadDialog, 'uploadcomplete', function(uploadPanel, manager, items, errorCount) {
var itemCount = items.length;
for(var i = 0 ; i < itemCount ; i++){
pathArray.push(items[i].getName());
}
console.log('---------- pathArray count = ' + pathArray.length);
var galleryStore = Ext.getStore('userProfileGallery');
var userStore = Ext.getStore('userStore');
var userModel = userStore.first();
//------------ Iterate through the items, create a model, then add model to the store
for(var j = 0 ; j < itemCount ; j++){
var personPhotoModel = Ext.ModelManager.create({
}, 'myappName.model.userPhoto');
var currentdate = new Date();
var uploadDate = currentdate.getDate() + "/" +
(currentdate.getMonth()+1) + "/" +
currentdate.getFullYear();
var uploadTime = currentdate.getHours() + ":" +
currentdate.getMinutes() + ":" +
currentdate.getSeconds();
personPhotoModel.set("image_path", "gallery/" + pathArray[j]);
personPhotoModel.set("description", "Gallery Image");
personPhotoModel.set("upload_date", uploadDate);
personPhotoModel.set("upload_time", uploadTime);
personPhotoModel.set("user_id", userModel.get('user_id'));
galleryStore.add(personPhotoModel);
console.log('gallery store count = ' + galleryStore.count());
}
//---------- sync the store here
console.log('gallery store count = ' + galleryStore.count());
galleryStore.sync();
}, this);
到目前为止,我尝试通过仅上传一个文件来制作 1 个模型,并且效果很好。但是,当我向商店添加超过 1 个模型然后同步商店时,无论我向模型中添加了多少项目,我都会得到一个空白行。
非常感谢任何帮助。谢谢。
【问题讨论】: