Updated examples
This commit is contained in:
parent
e0148db11f
commit
b6c155a199
4 changed files with 33 additions and 23 deletions
|
|
@ -5,10 +5,11 @@
|
|||
<script>
|
||||
var app = angular.module('myApplication', []);
|
||||
app.controller('postController', function($scope, $http) {
|
||||
var url = 'http://localhost/api.php/posts';
|
||||
$http.post(url,{user_id:1,category_id:1,content:"from angular"});
|
||||
$http.get(url).success(function(res){
|
||||
$scope.posts = php_crud_api_transform(res).posts;
|
||||
var url = '../api.php/posts';
|
||||
$http.post(url,{user_id:1,category_id:1,content:"from angular"}).success(function(){
|
||||
$http.get(url).success(function(response){
|
||||
$scope.posts = php_crud_api_transform(response).posts;
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ AppComponent =
|
|||
.Class({
|
||||
constructor: [
|
||||
ng.http.Http, function(http) {
|
||||
var url = "http://localhost/api.php/posts";
|
||||
var url = "../api.php/posts";
|
||||
http.post(url,JSON.stringify({user_id:1,category_id:1,content:"from angular2"})).subscribe();
|
||||
http.get(url).map(res => php_crud_api_transform(res.json())).subscribe(res => this.posts = res.posts);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,26 @@
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js"></script>
|
||||
<script src="../lib/php_crud_api_transform.js"></script>
|
||||
<script>
|
||||
$(function(){
|
||||
var url = 'http://localhost/api.php/posts';
|
||||
$.post(url, {user_id:1,category_id:1,content:"from knockout"});
|
||||
var url = '../api.php/posts';
|
||||
function PostList(){
|
||||
var self = this;
|
||||
self.posts = ko.observableArray([]);
|
||||
self.set = function(array) {
|
||||
self.posts.removeAll();
|
||||
for (i=0;i<array.length;i++) {
|
||||
self.posts.push(array[i]);
|
||||
}
|
||||
};
|
||||
self.update = function() {
|
||||
$.get(url, function(data) {
|
||||
$('#myApplication').html('<ul data-bind="foreach: posts"><li><span data-bind="text: id"></span>, <span data-bind="text: content"></span></li></ul>')
|
||||
ko.applyBindings(php_crud_api_transform(data),$('#myApplication')[0]);
|
||||
self.set(php_crud_api_transform(data).posts);
|
||||
});
|
||||
};
|
||||
$.post(url, {user_id:1,category_id:1,content:"from knockout"}, self.update.bind(self));
|
||||
};
|
||||
$(function(){
|
||||
$('#myApplication').html('<ul data-bind="foreach: posts"><li><span data-bind="text: id"></span>, <span data-bind="text: content"></span></li></ul>');
|
||||
ko.applyBindings(new PostList(),$('#myApplication')[0]);
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
|
|
|||
|
|
@ -5,27 +5,23 @@
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js"></script>
|
||||
<script src="../lib/php_crud_api_transform.js"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
var PostList = React.createClass({
|
||||
displayName: 'PostList',
|
||||
url: 'http://localhost/api.php/posts',
|
||||
|
||||
getInitialState: function getInitialState() {
|
||||
url: '../api.php/posts',
|
||||
getInitialState: function() {
|
||||
return { posts: [] };
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
$.post(this.url, {user_id:1,category_id:1,content:"from react"});
|
||||
retrieveServerState: function() {
|
||||
this.serverRequest = $.get(this.url, function (data) {
|
||||
this.setState(php_crud_api_transform(data));
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
$.post(this.url, {user_id:1,category_id:1,content:"from react"}, this.retrieveServerState);
|
||||
},
|
||||
componentWillUnmount: function() {
|
||||
this.serverRequest.abort();
|
||||
},
|
||||
|
||||
render: function render() {
|
||||
var createPost = function(post) {
|
||||
return React.createElement(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue