如何在存储中插入时接收错误
How to receive error while inserting in store?
我在AngularJS中使用angular indexedDB作为indexedDB。如果插入不成功,我希望收到错误。但我并没有得到任何错误,如果我运行两次相同的代码,它只是来自函数,因为我已经使名称唯一。
错误:
ConstraintError return _this.store.add(item);
约束错误请求=this.store.openCursor();
代码:
angular.module('myModuleName')
.controller('myControllerName', function($scope, $indexedDB) {
$scope.objects = [];
$indexedDB.openStore('people', function(store){
store.insert({"ssn": "444-444-222-111","name": "John Doe", "age": 57}).then(function(e){console.log('inside insert');});
store.getAll().then(function(people) {
// Update scope
$scope.objects = people;
});
});
});
我认为在promise .then
中添加错误回调应该可以使用
还要创建一个getAll方法来从objects
检索所有数据,在该方法中执行response.data
以获取从服务器返回的数据。
代码
angular.module('myModuleName')
.controller('myControllerName', function($scope, $indexedDB) {
$scope.objects = [];
$scope.getAll = function(){
store.getAll().then(function(response) {
// Update scope
$scope.objects = response.data;
});
};
$indexedDB.openStore('people', function(store){
store.insert({"ssn": "444-444-222-111","name": "John Doe", "age": 57})
.then(function(e){
console.log('inside insert');
//reload data only call get succeed
$scope.getAll();
}, function(error){
//do error handling stuff here
//you will get error returned from server here.
console.log('Error here', error)
});
});
});
相关文章:
- 使用.format在一些HTML代码中插入文本,会出现错误(Python)
- 如何将对象插入对象列表的开头,当它有 unshift 不是函数错误
- 在列表项中插入错误值的文本输入
- DOM插入的简单javascript错误
- 猫鼬查询/插入无序错误
- Array.insert函数错误,因为Object函数Array(){〔本机代码〕}没有方法'插入'
- 如何在存储中插入时接收错误
- 未捕获的类型错误:无法在“CSSStyleSheet”上执行“插入规则”:需要 2 个参数,但仅存在 1 个参数
- 使用节点在 rethindb 中插入错误
- JQUERY AJAX 发布错误 500 知道吗?我正在尝试将记录插入其中
- 使用 knex 从文件读取并插入数据库结束错误
- 在尝试将插入值从javascript调用到Visual Studio中的sql服务器时,收到内部服务器错误500
- 简单的“删除工作表/插入工作表”脚本上的服务器错误
- 使用 JS 将字符串插入到 SQLite,没有语法错误
- Google 云端硬盘 API 父项插入错误“需要资源元数据”
- 值未从输入错误插入数据库:phonegap中未定义
- 收集后POST响应错误.插入NodeJS Mongo模块
- 使用REST表单webpart: 403错误插入列表项,即使X-RequestDigest存在
- 关键错误插入到MongoDB使用node.js失败的一些对象没有任何键包含一个点
- 用angular,php和mysql错误插入记录到数据库