|
@@ -3,7 +3,7 @@
|
3
|
3
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.1/mustache.min.js"></script>
|
4
|
4
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js"></script>
|
5
|
5
|
<script src="../lib/php_crud_api_transform.js"></script>
|
6
|
|
-<script id="PostList_Item" type="x-tmpl-mustache">
|
|
6
|
+<script id="PostList_Item" type="text/mustache">
|
7
|
7
|
<ul>
|
8
|
8
|
{{#posts}}
|
9
|
9
|
<li>
|
|
@@ -19,10 +19,8 @@
|
19
|
19
|
</ul>
|
20
|
20
|
</script>
|
21
|
21
|
<script>
|
22
|
|
-var PostList = new (function(){
|
|
22
|
+function PostList(element, template) {
|
23
|
23
|
var self = this;
|
24
|
|
- var element = null;
|
25
|
|
- var template = null;
|
26
|
24
|
var url = '../api.php/posts';
|
27
|
25
|
self.delete = function() {
|
28
|
26
|
var id = $(this).attr('key');
|
|
@@ -34,7 +32,7 @@ var PostList = new (function(){
|
34
|
32
|
$.post(url, {user_id:1,category_id:1,content:content}, self.update);
|
35
|
33
|
};
|
36
|
34
|
self.render = function(data) {
|
37
|
|
- $(self.element).html(Mustache.to_html($(self.template).html(),php_crud_api_transform(data)));
|
|
35
|
+ $(element).html(Mustache.to_html($(template).html(),php_crud_api_transform(data)));
|
38
|
36
|
};
|
39
|
37
|
self.update = function() {
|
40
|
38
|
$.get(url, self.render);
|
|
@@ -42,15 +40,11 @@ var PostList = new (function(){
|
42
|
40
|
self.post = function() {
|
43
|
41
|
$.post(url, {user_id:1,category_id:1,content:"from mustache"}, self.update);
|
44
|
42
|
};
|
45
|
|
- self.init = function(element,template) {
|
46
|
|
- self.element = element;
|
47
|
|
- self.template = template;
|
48
|
|
- $(self.element).on('submit','form',self.submit);
|
49
|
|
- $(self.element).on('click','a',self.delete)
|
50
|
|
- self.post();
|
51
|
|
- }
|
52
|
|
-})();
|
53
|
|
-$(function(){ PostList.init('#myApplication','#PostList_Item'); });
|
|
43
|
+ $(element).on('submit','form',self.submit);
|
|
44
|
+ $(element).on('click','a',self.delete)
|
|
45
|
+ self.post();
|
|
46
|
+};
|
|
47
|
+$(function(){ new PostList('#myApplication','#PostList_Item'); });
|
54
|
48
|
</script>
|
55
|
49
|
</head>
|
56
|
50
|
<body>
|