最佳答案
看到这篇文章我相信是你想要的:Knockout catching errors , 但也请查看代码片段,也许会给您一些想法:
var ErrorHandlingBindingProvider = function() {
var original = new ko.bindingProvider();
//determine if an element has any bindings
this.nodeHasBindings = original.nodeHasBindings;
//return the bindings given a node and the bindingContext
this.getBindings = function(node, bindingContext) {
var result;
try {
result = original.getBindings(node, bindingContext);
}
catch (e) {
//here you will do what you you want to do to show to user
if (console && console.log) {
console.log("Error in binding: " + e.message);
}
}
return result;
};
};
ko.bindingProvider.instance = new ErrorHandlingBindingProvider();
snippet by : RP Niemeyer
关于javascript - 停止击倒错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34267505/