2013-05-08 106 views
-1

我有一個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? 
} 

上述格式是可以接受的嗎?

+0

無論你爲我工作,我會說。 angular.js已經爲使用AJAX的服務提供支持。 – akonsu 2013-05-08 16:57:45

回答

1

你有什麼可以。您可能遇到的問題是,如果您與服務器的交互不能清楚地落入一個模型對象的領域,那麼您的模型層將變得雜亂無章。

爲什麼不做你在服務器上做的事情,並創建一個服務層?

App.API = { 

    login: function(onSuccess) {....} 

    findBook: function(id, onSuccess) {....} 


}