建议如何创建一个JavaScript类
问题描述:
我有一个Java应用程序与此体系结构:实体+持久+业务+ REST服务。建议如何创建一个JavaScript类
我想创建没有JSF的视图层,换句话说,我只想使用HTML + CSS + JS(JQuery + Ajax)。
什么是更好的方式来创建一个JavaScript类来访问REST服务?
var Bookmark = function() {
this.id;
this.description;
this.link;
};
Bookmark.prototype._insert = function() {
// here should i put the JQuery Ajax Call?
};
Bookmark.prototype._delete = function() {
// here should i put the JQuery Ajax Call?
}
Bookmark.prototype._update = function() {
// here should i put the JQuery Ajax Call?
}
Bookmark.prototype._findById = function() {
// here should i put the JQuery Ajax Call?
}
Bookmark.prototype._findById = function() {
// here should i put the JQuery Ajax Call?
}
上述格式是可以接受的吗?
答
你有什么可以。您可能遇到的问题是,如果您与服务器的交互不能清楚地落入一个模型对象的领域,那么您的模型层将变得杂乱无章。
为什么不做你在服务器上做的事情,并创建一个服务层?
App.API = {
login: function(onSuccess) {....}
findBook: function(id, onSuccess) {....}
}
无论你为我工作,我会说。 angular.js已经为使用AJAX的服务提供支持。 – akonsu 2013-05-08 16:57:45