Skip to content
Advertisement

Getting BackBone.JS to set up a form and fill in the data

I am very new to backbone and I am trying to get my head around it, but can not figure out what I am doing wrong. I am not using backbones router, I do not need to, I am using PHP Slim to handle all the routes, I am not sure if that is right or not?

But what I have tried to do sort of works and sort of does not. This works fine without any errors:

JavaScript

This builds my form and displays this out without any problems at all. But when I try this, it does not work,

JavaScript

With this I get myformid not undefined within the console.

I have tried adding something like var myformid = null before the backbone view?

I love the idea of backbone, I will just say that their website could do with some more examples, which would make learning it easier.

So What am I doing wrong?

My end goal would be to build a new view object with data held within my database, output this data to a form pre-populated with my database data. Then use .save form backbone to get PHP Slim to to update the data within the db.

Advertisement

Answer

JavaScript

Adding initialize method and assigning options to this.options should do the job.

Added fiddle. Check it. I removed the other snippet as it doesn’t work.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement