Skip to content

can't manipulate the data in postgres #1

@lrAlval

Description

@lrAlval

This is My JS Code

tasks = new SQL.Collection("tasks");

if (Meteor.isClient) {

    tasks.createTable({
        id: ['$number'],
        text: ['$string'],
        checked: ['$bool', {$default: false}],
        createdAt: ['$datetime']
    });


    Template.body.helpers({
        tasks: function () {
            return tasks.select().fetch();
        }
    });

    Template.body.events({
        "submit .new-task": function (event) {
            event.preventDefault();
            var text = event.target.text.value;
            tasks.insert({
                text: text,
                createdAt: new Date()
            }).save();
            event.target.text.value = "";
        }
    });


    Template.task.events({
        "click .toggle-checked": function () {
            tasks.update({
                id: this._id,
                "checked": !this.checked
            }).where("id = ?", this.id).save();
        },
        "click .delete": function () {
            tasks.remove().where("id = ?", this.id).save();
        }
    });
}

if (Meteor.isServer) {
    tasks.createTable({
        id: ['$number'],
        text: ['$string'],
        checked: ['$bool', {$default: false}],
        createdAt: ['$datetime']
    }).save();

    tasks.publish('Tasks', function () {
        return tasks.select().save();
    })
}

this is my html Code

<head>
    <title>Todo List</title>
</head>

<body>
<div class="container">
    <header>
        <h1>Todo List</h1>

        <form class="new-task">
            <input type="text" name="text" placeholder="Type to add new tasks" />
        </form>
    </header>

    <ul>
        {{#each tasks}}
            {{> task}}
        {{/each}}
    </ul>
</div>
</body>

<template name="task">
    <li class="{{#if checked}}checked{{/if}}">
        <button class="delete">&times;</button>

        <input type="checkbox" checked="{{checked}}" class="toggle-checked"/>

        <span class="text">{{text}}</span>
    </li>
</template>

and this is the error log :

TypeError: Cannot call method 'query' of null

please help me i cant find the mistake;

thanks in
advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions