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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:07:31+00:00 2026-06-04T12:07:31+00:00

I have already define a model use backbone: window.ResourceModel = Backbone.Model.extend({ default:{ ‘relativeurl’:’unknow’, ‘type’:

  • 0

I have already define a model use backbone:

window.ResourceModel = Backbone.Model.extend({

        default:{
            'relativeurl':'unknow',
            'type': "unkonw"
        },

        initialize: function(){

            this.bind("change:relativeurl", function () {
                console.log('change!',this.relativeurl);
            });

            this.bind("change:type", function () {

            });
        },

        setRelativeURL: function (url) {
             console.log('pass in',url);//this have value
             this.set({"relativeurl": url});//this's value is undefined!
        },

        delResource: function () {
            console.log("this.url",this.relativeurl);
            resourceMasterView.delResourceItem(this.url);
        }
    });

Then I want invoke this method

window.resourceModel = new ResourceModel();
resourceModel.setRelativeURL(url);
resourceModel.setType(type);

but just I comment above,even I already invoke the set method ,the “relativeurl” result is still undefined!

What’s wrong with my code?How can I solve this problem?

  • 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-04T12:07:32+00:00Added an answer on June 4, 2026 at 12:07 pm

    To access the relativeurl attribute of a Backbone model, you say m.get('relativeurl'); the attribute is not stored as a property of the model so this:

    console.log('change!', this.relativeurl);
    

    will always yield undefined for this.relativeurl. You should say:

    console.log('change!', this.get('relativeurl'));
    

    Demo: http://jsfiddle.net/ambiguous/VBQ5h/

    You could also access the attribute directly through this.attributes but you should usually leave attributes alone:

    console.log('change!', this.attributes.relativeurl);
    

    Demo: http://jsfiddle.net/ambiguous/y3Q6b/

    Your real problem is probably confusion between object properties and Backbone attributes. Properties are fields of the object and are accessed as o.some_property or o['some_property']. Backbone models deal primarily with attributes which are stored in the model’s attributes property and are accessed through get and modified through set (and of course fetch, unset, and clear). Backbone models don’t know anything about arbitrary object properties.

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

Sidebar

Related Questions

I have a MongoMapper model called LogInfo that has a number of fields already
We use XML to define a model which we later use to generate code.
Say I have models: class Animal(models.Model): type = models.CharField(max_length=255) class Dog(Animal): def make_sound(self): print
i have a object in javascript and some already defined functions. but how can
I have a Java array defined already e.g. float[] values = new float[3]; I
I have already created a webpart to show the data from list, but I
I have already posted a question about this, but the situation has changed sufficiently
I have already search for some time over the net on how to create
I have already a site with a single homepage index.php which accepts 2 parameters
I have already implemented some AJAX pagination in my Rails app by using the

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.