G
G
Grigory Dikiy2016-08-09 18:25:35
JavaScript
Grigory Dikiy, 2016-08-09 18:25:35

JavaScript context binding?

Good afternoon. Please tell me how can I bind the context to taskListStorage.find ?

import React from 'react';
import taskListStorage from '../data.js';

export default class TaskList extends React.Component{
  constructor(props) {
    super(props);

    this.state = {
      taskList: []
    }
  }

  getTaskListTemplate() {
    taskListStorage.find({}, (err, task) => {
        this.setState({taskList: this.state.taskList.push(task)});
    });
  }

  render() {
    this.getTaskListTemplate();
    return (
      <div>
        <h1>Task List</h1>
        <ul>
        </ul>
      </div>
    );
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sugadu, 2016-08-09
@frilix

getTaskListTemplate() {
var self = this;
    taskListStorage.find({}, (err, task) => {
        self.setState({taskList: self.state.taskList.push(task)});
    });
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question