|
@@ -43,15 +43,15 @@ function PostList(element,template) {
|
43
|
43
|
};
|
44
|
44
|
self.render = function(data) {
|
45
|
45
|
data = php_crud_api_transform(data);
|
46
|
|
- $(element).html($(template).html());
|
47
|
|
- var item = $(element).find('li').first().remove();
|
|
46
|
+ element.html(template.html());
|
|
47
|
+ var item = element.find('li').first().remove();
|
48
|
48
|
for (var i=0;i<data.posts.length; i++) {
|
49
|
49
|
var clone = item.clone();
|
50
|
50
|
clone.find('span').each(function(){
|
51
|
51
|
var field = $(this).attr("class");
|
52
|
52
|
$(this).text(data.posts[i][field]);
|
53
|
53
|
});
|
54
|
|
- clone.insertBefore($(element).find('li').last());
|
|
54
|
+ clone.insertBefore(element.find('li').last());
|
55
|
55
|
}
|
56
|
56
|
};
|
57
|
57
|
self.update = function() {
|
|
@@ -60,12 +60,12 @@ function PostList(element,template) {
|
60
|
60
|
self.post = function() {
|
61
|
61
|
$.post(url, {user_id:1,category_id:1,content:"from zepto"}, self.update);
|
62
|
62
|
};
|
63
|
|
- $(element).on('submit','form',self.submit);
|
64
|
|
- $(element).on('click','a.edit',self.edit)
|
65
|
|
- $(element).on('click','a.delete',self.delete)
|
|
63
|
+ element.on('submit','form',self.submit);
|
|
64
|
+ element.on('click','a.edit',self.edit)
|
|
65
|
+ element.on('click','a.delete',self.delete)
|
66
|
66
|
self.post();
|
67
|
67
|
};
|
68
|
|
-$(function(){ new PostList('#PostListDiv','#PostListTemplate'); });
|
|
68
|
+$(function(){ new PostList($('#PostListDiv'),$('#PostListTemplate')); });
|
69
|
69
|
</script>
|
70
|
70
|
</head>
|
71
|
71
|
<body>
|