Skip to content

esorribas/KnockRest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

KnockRest

A simple Knockout REST library for CRUD operations

Made with Knockout.js and jQuery

How to use it:

1) Create a Knockout model:
var myViewModel = {
    _id: ko.observable(''),
    username: ko.observable(''),
    firstName: ko.observable(''),
    list: ko.observableArray([])
};

ko.applyBindings(myViewModel);

We need to create a dummy "list" observableArray attribute to fetch all objects from API

2) Configure your KnockRest object:
var kr = new KnockRest('http://localhost:3000/api/users', myViewModel, '_id');
3) Attach event handlers:
$('#btnList').click(function() {
    kr.list();
});

$('#btnSave').click(function() {
    kr.save();
});

$('#btnDelete').click(function() {
    kr.delete();
});

$('body').on('click', '.load', function() {
    kr.get($(this).attr('id'));
});

About

A simple Knockout REST library for CRUD

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published