问题
I'm having a problem that I really can't comprehend… I'm not sure if backbone is doing some voodoo to these objects but I can't seem to get even raw access to them.
My basic problem is, sometimes when I load the page, fetch the models and render the views one collection will only show/render 50% of the time. I assumed this was an issue with the model not being populated but after some investigation, I could see the model was populated but not accessable.
Does anyone have any ideas? I have attached a few screenshots of working and not working to illustrate my point(sanity).
Page loading fine - model accessed
Page not loading correctly - model inaccessible
The object when is loading correctly
The object when not loading correctly
回答1:
Your debugging attempts are going wrong.
console.dir is a lot more complex then that. it shows you a live object, not the real object.
If you try to log $.extend(true, {}, obj)
(or some other clone) then you can log the real object.
As mentioned it sounds like an ajax thing. Are you trying to use it before it has loaded? (But sometimes you get lucky and it has loaded by then).
We need more information. A jsfiddle would be the best.
来源:https://stackoverflow.com/questions/6282451/backbone-js-inaccessible-object-attributes