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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:40:17+00:00 2026-05-31T20:40:17+00:00

I have this model var Item = Backbone.Model.extend({ url: ‘http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials’ }); var onSuccess

  • 0

I have this model

var Item = Backbone.Model.extend({
   url: 'http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials'
});

var onSuccess = function(){ alert("success"); };

And a collection

var Items = Backbone.Collection.extend({
    model: Item
});

And the rest of my code is here:

var item = new Item();
var items = new Items();
item.fetch({ success: onSuccess });
alert(items.get("ItemCode"));

What I want is to simply get the attributes of the model. Now I have this on firebug. Also when I run it on the browser I get the alert success and the next alert is undefined.
enter image description here

This is the output:

{"ErrorMessage":null,"Items":[{"ErrorMessage":null,"CategoryCode":"Event Materials","ClassCode":null,"Components":null,"GroupCode":null,"ImageURL":null,"ItemCode":"ITEM-123","ItemDescription":"Old World Lamppost\u000d\u000a\u000d\u000a","ItemName":"GET123","ItemType":null,"KitItem":null,"Matrix":null,"Prefix":null,"RetailPrice":107.990000,"SalesTaxCode":null,"UPCCode":null,"UnitMeasureCode":"EACH","UnitsInStock":0,"Value":null,"WholesalePrice":95.000000}]}

NOTE

That is just one of the items it returns. I just posted on item so that it won’t be that long.

  • 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-05-31T20:40:18+00:00Added an answer on May 31, 2026 at 8:40 pm

    You are calling get on your collection ( see http://documentcloud.github.com/backbone/#Collection-get)

    It seems what you really want is to iterate over the collection, and call get on each item

    items.each(function(item) {
      item.get('ItemCode');
    });
    

    If not, please elaborate!

    Additionally, if your model url responds with a list of models, you should be defining the url attribute in your Collection instead of your model.

    var Items = Backbone.Collection.extend({
        model: Item,
        url: 'http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials'
    });
    

    And your response should be an array, with Items as array elements [<item1>, <item2>, ...], rather than a JSON object with {'Items': [<item1>, <item2>, ...] }. If you don’t want to modify the response, you will have to implement the parse function on your collection ( http://documentcloud.github.com/backbone/#Collection-parse ).

    Also, as @chiborg mentions, you are calling get right after fetch (which will complete asynchronously), so there is no guarantee that your data will be available.

    The proper solution here is to bind a ‘refresh’ listener on the collection.

    items.on('refresh', function() {
      // now you have access to the updated collection
    }, items);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is what I have so far: var Item = Backbone.Model.extend({ defaults: { id:
I have this code <% foreach (var item in Model.List) { %> <tr> <td><%:
I have this html @foreach (var item in Model.Options) { <input type=checkbox checked=checked name=selectedObjects
I have code like this: <% foreach (var item in Model) { %> <tr>
I have a backbone model called Member - this contains membership data such as
I have this one in View: <% foreach (var item in (List<MyType>)ViewData[MyTypeArray]) { %><tr>
I have this view: @model MatchGaming.Models.ProfileQuery @{ ViewBag.Title = Index; } <h2>Index</h2> <script src=@Url.Content(~/Scripts/jquery.validate.min.js)
I have this piece of a HTML in a View: <% foreach (var item
I have a loop <ul id=news-list class=thumbobs-list> @foreach (var item in Model.News) { @Html.Partial(RenderNews/
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,

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.