Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:13:41+00:00 2026-06-03T06:13:41+00:00

I am trying to access items of an array in a model and it’s

  • 0

I am trying to access items of an array in a model and it’s raising errors but seems to be finding the correct attribute and writing it to the console still

class GD.Views.Place extends Backbone.View
  template: JST['mobile/templates/place']
  initialize: ->
    @model.on('change', @render, this)
  render: ->
    $(@el).html(@template(place:@model, open:@openNow() ))
    console.log @model.get("coordinates")
    console.log @model.get("coordinates")[0]
    console.log @model.get("coordinates")[1]
    console.log("done")
    this
  openNow: ->
    ...

The view is not rendering on-screen and I am seeing this message in my console

Uncaught TypeError: Cannot read property '0' of undefined
  GD.Views.Place.Place.render
  GD.Routers.Main.Main.place
  _.extend.route
  (anonymous function)
  _.some._.any
  _.extend.loadUrl
  _.extend.start
  window.GD.init
  (anonymous function)
  jQuery.Callbacks.fire
  jQuery.Callbacks.self.fireWith
  jQuery.extend.ready
  DOMContentLoaded
[51.4528837, -0.9739059999999428]
51.4528837
-0.9739059999999428
done

The error message is referring to the 2nd and 3rd console.log lines above. It also seems to be raising errors when accessing further attributes in embedded hashes.

I don’t understand why this is happening or how to work around it. Thanks for the help/patience in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:13:42+00:00Added an answer on June 3, 2026 at 6:13 am

    The usual pattern with a Backbone view is this:

    v = new V
    $(something).append(v.render().el)
    

    If you combine that with a common pattern for initializing a model:

    m = new M
    m.fetch() # asynchronous!
    

    then you can get this:

    m = new M
    m.fetch()
    v = new V(model: m)
    $(something).append(v.render().el)
    

    That would allow the v.render() inside the append call to happen before the model has been fetched from the server. In your case, that would mean that @model.get('coordinates') would be undefined in the v.render() call above and you would get:

    Uncaught TypeError: Cannot read property '0' of undefined
    ...
    

    then, the m.fetch() gets its data from the server and triggers a "change" event, that event would then call render on your view and you would get this:

    [51.4528837, -0.9739059999999428]
    51.4528837
    -0.9739059999999428
    done
    

    That sequence of messages is exactly what you’re seeing in your console.

    I’d guess that you’r doing something like this (as above):

    m = new M
    m.fetch()
    v = new V(model: m)
    $(something).append(v.render().el)
    

    Try checking to see if @model is actually loaded inside render and throw up some sort of “loading…” message if it isn’t; then let the "change" event trigger the “real” rendering.


    PS: You can use @ instead of this in CoffeeScript:

    initialize: ->
      @model.on('change', @render, @)
    render: ->
      #...
      @
    

    You could also use a fat arrow (=>) to define your render method and not worry about supply a context to @model.on:

    initialize: ->
      @model.on('change', @render)
    render: =>
      #...
      @
    

    Furthermore, if you’re using a recent version of Backbone, you have a $el in your view instances so you could:

    render: =>
      @$el.html(...)
      #...
      @
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to access items in an array of structs and print the
im retrieving the Array of JSON data and trying to diplay and access it.But
I'm trying to access a member structs variables, but I can't seem to get
I'm hitting a wall here while trying to access items from Magento on an
I'm trying to access a variable in a smarty array. The array is called
I'm new to JSON and ajax, but i'm trying to access data in an
I'm trying to walk through a bunch of items, each item has an array
When trying to access an element deep in an array of arrays, what is
Im trying to loop through a json files' object array to access its variables'
I have an array in an xml file that i'm trying to access, however

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.