Backbone.js inaccessible object attributes

本秂侑毒 提交于 2020-01-06 05:49:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!