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 8660197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:11:49+00:00 2026-06-12T16:11:49+00:00

I’m new to Backbone + new to CoffeeScript. I have a collection which retrieves

  • 0

I’m new to Backbone + new to CoffeeScript. I have a collection which retrieves data (properties) from a URL. In my homeView I append this data to a template and loop through it:

<ul>
     <% _.each(data, function (row) { %>
          <li><%= row.get('name') %></li>
     <% }); %>
</ul>

This works fine.

However, when I want to view an individual row (property), I still use the same collection and change an attribute in my model (id), to change the URL being called in the collection & retrieve only one piece of data (one property).

The way I have coded it is, in my individual property view, it still loops through the collection (even though there’s only on row), and appends it to the main view

class ShowPropertyView extends Backbone.View
    constructor: ->
        super

    initialize: ->
        @Property = new PropertyCollection #New collection
        @Property.PropertiesModel.set({theID: @options.theID}) #Change URL and get one property with a specific ID

    template: _.template($('#showProperty').html())
    #propertyInfoTemplate: _.template($('#propertyInfoTemplate').html())

    render: ->
        #$(@.el).html(@template) #load main template
        @loadResults() #load individual property

    loadResults: ->
        @Property.fetch({
            success: (data) =>
                         $('#propertyInfo').append(@propertyInfoTemplate({data: data.models, _:_})) #Load data into another template & append template to main template
            error: ->
                alert('Unable to load information')
        })

And the current template (which receives the data & gets appended to the main template) looks like this (which is similar to my homeView template):

<div>
     <% _.each(data, function (row) { %>
          <div>
               <h3><%= row.get('name') %></h3>
          </div>
     <% }); %>
</div>

Want I need to achieve is the ability to pass the information into the one single view, and remove the need for the looping statement in underscore and not have to append this to the main view (as it’s just only an individual piece of data).

so I just have one single view that just looks like this:

<div>
     <h3><%= row.get('name') %></h3>
</div>

I no I need to change something in ShowPropertyView, I’m just not sure what?
Any help would be much appreciated! Thanks.

  • 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-12T16:11:50+00:00Added an answer on June 12, 2026 at 4:11 pm

    I think that the best idea to solve your problem is to split described functionality into two views. I really recommend to use backbone.js convention to implement simple views by passing to their constructors model instance or collection instance, like in docs.

    The code for this solution is shown below. Firstly view for one model

    class OnePropertyView extends Backbone.View
    
      template: _.template($('#oneProperty').html())
    
      render: ->
        @model.fetch
          success: =>
            $('#propertyInfo').append(@template({model: @model}))
    

    And template for that:

    <div>
        <h3><%= model.get('name') %></h3>
    </div>
    

    Code for collection view:

    class CollectionPropertyView extends Backbone.View
    
      template: _.template($('#collectionProperty').html())
    
      render: ->
        @collection.fetch
          success: =>
            $('#propertyInfo').append(@template({collection: @collection}))
    

    And template for collection handling:

    <ul>
        <% collection.forEach(function (model) { %>
            <li><%= model.get('name') %></li>
        <% }); %>
    </ul>
    

    Code above you can use it like that, for example in your router:

    model = new PropertyModel(id: modelId) # modelId retrived from URL
    view = new OnePropertyView(model: model)
    view.render()
    

    and for collection

    collection = new PropertyCollection();
    view = new CollectionPropertyView(collection: collection)
    view.render()
    

    Sometimes when collection view is a bit complicated, for example with some actions for every row, it is good to implement a nested view (that represents row). This approach is simpler and more legibility, because for every row you can use events mapping.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I

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.