Introducing easy JavaScript data access
So you want to rapidly prototype a really cool Web 2.0 JavaScript application, but you don’t want to spend all your time writing the wiring code to get to the database? Traditionally, to get data all the way from the database to the front end, you need to write a class for each table in the database with all the create, read, update, and delete (CRUD) methods. Then you need to put some marshalling code atop that to provide an access layer to the front end. Then you put JavaScript libraries on top of that to access the back end. What a pain!
This文章介绍了一种替代方法,在该方法中,您使用单个数据库类来包装多个数据库表.单个驱动程序脚本将前端连接到后端,前端的另一个包装类使您可以访问所需的所有表.
实施例/使用
// Sample functions to update authors
function updateAuthorsTable() {
dbw.getAll( function(data) {
$('#authors').html('
ID | Author |
$(data).each( function( ind, author ) {
$('#authors tr:last').after('
'+author.id+''+author.name+'');});
});
}
$(document).ready(function() {
dbw = new DbWrapper();
dbw.table = 'authors';
updateAuthorsTable();
$('#addbutton').click( function() {
dbw.insertObject( { name: $('#authorname').val() },
function(data) {
updateAuthorsTable();
});
});
});
我认为这正是你要找的.这样您就不必自己构建它.