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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:01:39+00:00 2026-06-14T08:01:39+00:00

I’ve got a simple div into which I’d like backbone to render a select

  • 0

I’ve got a simple div into which I’d like backbone to render a select box and options from my server.

The options seem to render just fine, but the select box does not. I’m sure it’s a simple tweak, but can’t seem to find it.

I created a simplified fiddle for it: http://jsfiddle.net/thunderrabbit/BNZY3/

The HTML

<div id="where_fields"></div>

The script I’m using uses fetch() to get the data. The Fiddle above hardcodes the data, but the issue is the same.

(function($){
    var Field = Backbone.Model.extend();

    var UnitFields = Backbone.Collection.extend({
        url: '/<?php echo CONFIG_ADMIN_DIR; ?>/api/fieldnames/units',
        model: Field
    });

    var BuildingFields = Backbone.Collection.extend({
        url: '/<?php echo CONFIG_ADMIN_DIR; ?>/api/fieldnames/buildings',
        model: Field
    });

    var FieldView = Backbone.View.extend({
        tagName: "option",

        initialize: function(){
            _.bindAll(this, 'render');
        },
        events: {
            "click":"clicked"
        },
        clicked: function(e) {
            var data_type = this.model.get("DATA_TYPE");
            if(data_type == "varchar") {
                console.log("it's a varchar");
            }
            if(data_type == "int") {
                console.log("it's an int");
            }

        },
        render: function(){
            $(this.el).attr('value', this.model.get('COLUMN_NAME')).html(this.model.get('display_name'));
            return this;
        }
    });

    var FieldsView = Backbone.View.extend({
        tagName: "select",
        el: $('#where_fields'),
        initialize: function(){
            _.bindAll(this, 'render', 'renderItem');
            this.collection.bind('reset', this.render);
        },
        renderItem: function(model) {
            console.log('rendr item');
            var fieldView = new FieldView({model:model});
            fieldView.render();
            $(this.el).append(fieldView.el);
        },
        render: function(){
            console.log('rendr');
            this.collection.each(this.renderItem);
            return this;
        }
    });

    var units_fields = new UnitFields();
    var buildings_fields = new BuildingFields();

    var unitsView = new FieldsView({collection: units_fields});
    var buildingsView = new FieldsView({collection: buildings_fields});

    units_fields.fetch();
    buildings_fields.fetch();

})(jQuery);

Why is my backbone script not rendering the select tags?

  • 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-14T08:01:41+00:00Added an answer on June 14, 2026 at 8:01 am

    You have both tagName and el attributes in your FieldsView class. You don’t need both. Use tagName if you want to render a view detached from the DOM and then backbone will use that tag instead of the default of div. However, in your render(), you don’t ever actually get a select tag involved. $(this.el) is your #where_fields div and you just append fieldView.el, which is an option element. That’s why there is no select element. Some quick tips:

    • use this.$el as a more efficient shorthand for $(this.el)
    • It’s preferable to keep your view loosely coupled from the DOM, so el: $('#where_fields') is not as clean a design as rendering an element detached from the DOM and letting other code decide where exactly in the existing DOM it should be attached.
    • So you should remove your el properly, set tagName to select if you like, then your render() method will be doing what you want with is appending options to a select tag, then move the actual code to append your view’s rendered el to the #where_fields div out of the view into your router perhaps.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group
I am currently running into a problem where an element is coming back from
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

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.