Updated examples

This commit is contained in:
Maurits van der Schee 2016-04-08 21:01:30 +02:00
commit b6c155a199
4 changed files with 33 additions and 23 deletions

View file

@ -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"});
this.serverRequest = $.get(this.url, function (data) {
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(