-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknockrest.html
76 lines (63 loc) · 2.03 KB
/
knockrest.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
</head>
<body>
<div>
Id: <input type="text" data-bind="value: _id" readonly>
Username: <input type="text" data-bind="value: username">
First name: <input type="text" data-bind="value: firstName">
</div>
<hr>
<button id="btnList">Click to get all</button>
<button id="btnSave">Click to save current</button>
<button id="btnDelete">Click to delete current</button>
<hr>
<table cellpadding="5">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>First Name</th>
<th> </th>
</tr>
</thead>
<tbody data-bind="foreach: list">
<tr>
<td data-bind="text: _id"></td>
<td data-bind="text: username"></td>
<td data-bind="text: firstName"></td>
<td>
<button type="button" class="load" data-bind="attr: { id: _id }">Load</button>
</td>
</tr>
</tbody>
</table>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js"></script>
<script src="knockrest.js"></script>
<script type="text/javascript">
var myViewModel = {
_id: ko.observable(''),
username: ko.observable(''),
firstName: ko.observable(''),
list: ko.observableArray([])
};
ko.applyBindings(myViewModel);
var kr = new KnockRest('http://localhost:3000/api/users', myViewModel, '_id');
$('#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'));
});
</script>
</body>
</html>