I’m making a Todo app/webservice but my knowledge to meteor and mongodb is still limited, normally i work with mySQL and PHP
I have made a todolist with categories but now i would like to add sub levels and when pushing the add + button it will insert a new category in my category collection with the parent it, if you are in a sub level.
1. howto get the parent Id from the url?
tasks/oKZnTPYFEZKLthEPx
and insert it into the parent_id field in my categories collection
2. how to make and if else that says:
if there is no Id in the url
/tasks
then show all categories where there is no parent_id else show where parent is tasks/_id
You aren’t really providing enough of your code for anyone to solve the problem.
Are you asking how to design your categories collection? There are plenty of ways, but two options would be either nest your tasks within the category, or create a tasks collection with a category field that references the parent category id, and an array of task ids within the category collection.
And if you mean how do you access the actual id from the url, with Iron router you should be able to grab the id by using Router.current().params._id (i believe that is the proper syntax, but if not just type Router.current() into your console and climb down the object until you find the id).
I am not going to walk you through how to build your app, but from what you posted it looks like there should be two separate routes, and two separate templates.
Make a /tasks route that points to a general tasks feed instead of checking if there is an id in the route and using the same template.
Be sure to read through guide.meteor.com. The section on URLs and routes is very helpful.