我有以下 HTML 错误消息:
<div class="alert alert-error">
<div class="content">
<p>
<i class="fa fa-warning"></i>
User not found.
</p>
</div>
</div>
如何在 Backbone 中向用户显示它,并且不会失去良好的实践?
我的意思是,让我的 View 可靠地渲染它的最佳方法是什么?
此消息何时显示?
user.save({}, {
success: function(model, response) {
if (response.error) {
// hey, the message goes here!
}
}
});
最佳答案
您可以使用新方法扩展 Backbone View 来显示如下错误:
_.extend(Backbone.View.prototype, {
showError: function(message) {
// Here you render your error, may be like this : $('#errorInfo').html(message);
}
});
在您看来:
var self = this; // I assume that you are in the view
user.save({}, {
success: function(model, response) {
if (response.error) {
self.showError(/* things you want to pass */);
}
}
});
关于javascript - 将错误消息从 Controller 传递到 Backbone 进行查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21575171/