2014년 12월 9일 화요일

[backbonejs] problems with updating backbone version to the newest....1.1.2

In the previous version of backbone,in my app,I never used model/view binding...my app worked without it.

Now,with the newest version it seems I have to....but some problem appeared.

This is the  script and in lines 40-41 I make one model/view binding related to the one(of 2) views of the script.

The jsbin is here.

The problem now:
If you got to the output pane of jsbin and click so that you can enter that data for an event...everything goes well and the event is "passed" to the calendar.

But if you click the newly-created event....I get the following error(the function that is called is at line 130):
Cannot read property 'isNew' of undefined 

This relates with the line 179 at the script(see the link I gave you...not jsbin).

After a search I made it seems that the cause of the problem is found at line 136.
I do not why, but no Id is passed to the model....all other data related to the event/model are passed,except an Id.

I mean the model is undefined(as the error suggests) because fcEvent.id(136) gets to be undefined also.

I do not know why this happens...
I got the following error in the previous version but i was able to deal with it by just getting from the server(json response) the Id of the model.
If I refresh the page the problem disappears....
I really cannot understand what is missing here.



Does your data have an “id” column? Unless it’s in your data, or when you extend the model, you specifically set “idAttribute,” you’d have to set it directly.

idAttributemodel.idAttribute
A model's unique identifier is stored under the id attribute. If you're directly communicating with a backend (CouchDB, MongoDB) that uses a different unique key, you may set a Model's idAttribute to transparently map from that key to id.
var Meal = Backbone.Model.extend({
  idAttribute: "_id"
});



In the previous of version of backbone...there was no need to set an id attribute directly...why do it now?
My database has a column Id...and as I said,the json response(event data) from the server contains an ID.
The id for the events is produced by the DBMS...it is an auto increment column whose value is returned to the client in JSON format.
(When creating an event(POST request)...related data(startdate,enddate etc...) are sent to the server and the response of the server is the ID)
And this value of course passes to the model....by updating backbone this no longer happens,unless I refresh the page.
I am still trying to solve the issue...maybe some code changes are needed,but I do not know which exactly
I am going to reinstate the problem....one of the views of the code is found on line 159.
The model is found at line 5.
I have this question:
How am I going to bind these two?Maybe this is the solution to the problem.
Cause we are dealing here with an undefined model.

댓글 없음:

댓글 쓰기