0

I am writing a module based javascript website, backed by a Mysql DB.

Each module talks with the DB through PHP. On the UI, for simplicity, the module on the left will display all relevant rows, with edit(write) functionality. The module on the right display the data from the same DB, with write access too. So each would affect the other in each update.

I'm told backbone would be a good framework. Then, I have read the todos example, and understand how there are item->itemList, view->viewList, etc...

But now, the question is, how do I apply it to this situation?

Which is an item, a view in this situation?

1 Answer 1

1

The module on the left and the module on the right are Views, each of which can be made up of other views.

Within the model don't store a reference to the view (as I've seen done in some of the examples):

this.view = view; //view being passed in as an arg

The reverse (a view storing a reference to a model) is okay. Your views should be doing most of the work, listening to and responding to model events. Thus, in the view initialize method you might:

model.bind("interesting-event", function(){
  //the view updates/reacts to the model.
});

Also, never add a model to two collections (just one ever). When a model is assigned to a collection, Backbone sets a reference on the model that points to the owning collection.

Incidentally, the a-model-cannot-belong-to-two-collections issue is the reason why you don't want a model referencing its view. A model can have many views on one screen.

Backbone is perfect for your needs. Start with a very basic version of your app and keep fleshing it out. All the while keep reading about Backbone online. I read everything I could find (there's not a whole lot, not really). The key concept is simply event based programming (much like you'd use in VB or lots of other platforms). It's a lot of trial and error, but you'll make sense of it with practice.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for answering my questions about backbone.js. Ya, I couldn't really find any beginner level example that really demonstrates what I have in mind. Still trying to understand how backbone.js would work for me. Correct me if i'm wrong in anyway... I pull a table of users from a DB, each row(ie. a user) would become a model. Together they form a collection. The appView that form the overall UI would encompass the individual views for each model. When a viewModel is triggered, it'll get any info necessary from its associated model and re-render that model only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.