Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // live preview @ https://preview.c9.io/weee/diabeteslog_react/index.html#records
- // react version: 0.12.1
- // Ctrl + F "BUG" to highlight relevant lines
- var Records = React.createClass({
- mixins: [ReactFireMixin],
- getInitialState: function () {
- return {records: {}};
- },
- render: function() {
- var records = this.state.records;
- return <table className="table">
- <thead>
- <tr><th>Timestamp</th>
- <th>Glucose (mg/dl)</th>
- <th>Carbs (grams)</th>
- <th>Bolus (units)</th>
- <th>Basal (units)</th>
- <th>Notes</th>
- </tr>
- </thead>
- <tbody>
- {Object.keys(records).reverse().map(function(key) {
- return <tr key={key}>
- <td>{(new Date(records[key].timestamp)).toLocaleString()}</td>
- <td>{records[key].glucose}</td>
- <td>{records[key].carbs}</td>
- <td>{records[key].bolus}</td>
- <td>{records[key].basal}</td>
- <td><button id="mrButton" onClick={this.noteClick}>Click</button></td> //BUG: doesn't register event
- </tr>;
- })}
- </tbody>
- </table>;
- },
- noteClick: function (event) {
- //BUG: this should getting triggered, but its not.
- alert("callback reached");
- },
- componentWillMount: function() {
- this.bindAsObject(
- new Firebase("https://diabeteslog.firebaseio.com/records/"),
- "records");
- },
- componentDidUpdate: function() {
- var buttons = $(this.getDOMNode()).find('button');
- var buttonCount = 0;
- var recordCount = Object.keys(this.state.records).length;
- buttons.each(function() {
- buttonCount += 1;
- })
- //BUG: this works fine
- //buttons.click(this.noteClick);
- console.log(recordCount === buttonCount ?
- "record and button count match" :
- "record and button count don't match");
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement