Hi,
I’m sure I’m doing something very trivial wrong, but I’m not at all familiar with this stack and from what I can see, things look right.
I am doing the Svelte-based todo list tutorial, having modified it slightly to fit my use case. Right now, that just means “tasks” are called “categories” instead.
At the end of step 2.3, I am meant to see my inserted categories show up on the page. However, I am seeing the correct HTML elements with “undefined” rather than the category text.
I’ve already debugged mongoDB insertion and that all looks like it’s going fine, so somewhere throughout the rendering process I must have made a mistake that I can’t find for the life of me.
I have the following code:
in App.svelte:
<script>
import { Meteor } from "meteor/meteor";
import Category from "./Category.svelte";
import { CategoriesCollection } from "../api/CategoriesCollection";
$m: categories = CategoriesCollection.find({}).fetch()
// more information about $m at https://atmospherejs.com/zodern/melte#tracker-statements
</script>
//SNIP
{#each categories as category (category._id)}
<Category category={category} />
{/each}
In server/main.js:
import { Meteor } from 'meteor/meteor';
import { CategoriesCollection } from '/imports/api/CategoriesCollection';
const insertCategory = categoryText => {
console.log(categoryText)
const id = CategoriesCollection.insert({ categoryText });
console.log(id);
}
Meteor.startup(async () => {
if (await CategoriesCollection.find().countAsync() === 0) {
[
'First dinner',
'Second Dinner',
'third dinner',
'Fourth dinner',
'Fifth Dinner',
'Sixth Dinner',
'breakfast'
].forEach(insertCategory)
}
});
In imports/api/CategoriesCollection.js:
import { Mongo } from "meteor/mongo";
export const CategoriesCollection = new Mongo.Collection("categories");
And finally in the Category.svelte component:
<script>
export let category;
</script>
<h2> { category.text }</h2>