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

  • Home
  • SEARCH
  • 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 7800779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:44:50+00:00 2026-06-02T00:44:50+00:00

BASIC QUESTION I am trying to send an object through socket.emit() but the object

  • 0

BASIC QUESTION
I am trying to send an object through socket.emit() but the object is not being fully sent. I may just be misunderstanding how to do this, but here’s the example:

console.log(object)

RESULTS IN

{ length: 8,
  models:
   [ { attributes: [Object],
       _escapedAttributes: {},
       cid: 'c1',
       changed: {},
       _silent: {},
       _pending: {},
       _previousAttributes: [Object],
       lots: [Object],
       _changing: false,
       collection: [Circular],
       _callbacks: [Object] },
    ... ETC

While

socket.emit(e,object);

RESULTS IN :

{"name":"read:AllAuctions","args":
[[{"auctionId":"298"},{"auctionId":"381"},{"auctionId":"385"},
{"auctionId":"393"},{"auctionId":"394"},{"auctionId":"395"},
{"auctionId":"402"},{"auctionId":"800"}]]}

It arrives to the front-end in the latter format.

WAY MORE DETAIL
I’ve created a server that is attempting to update a client-side backbone model using socket.io. Some of it is using the ideas specified here:

http://developer.teradata.com/blog/jasonstrimpel/2011/11/backbone-js-and-socket-io

The difference is that I’ve created backbone models on the back end. My logic was to share the basic model files, and have the back-end deal with communicating with the persistance layer and keeping the “true” data source optimized, but then respond to requests to fetch those models/collections as well as automatically pushing updates.

Everything seems to be working except for however I’m supposed to transfer the model to the front-end. Do I need to extend/overwrite toJSON or another method that actually converts it for transport? If so, how do I do that? Any help you can give me would be greatly appreciated!

  • 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-02T00:44:52+00:00Added an answer on June 2, 2026 at 12:44 am

    I hate to answer my own question, but I found the problem in another question:
    Saving Backbone model and collection to JSON string

    Essentially, what I didn’t realize was that toJSON() only returns the attributes of the model. My models contained a collection of other models, so I needed to overwrite toJSON().

    Collections call the toJSON() of their child model. So, I ultimately needed to change the model’s toJSON function to return the attributes AND the collection of models they contained.

    Here’s the example:

    var Auction = Backbone.Model.extend({
      defaults: {
        auctionId : null
      },
      toJSON : function() {
        var returnObject = {};
        returnObject["auctionId"] = this.get("auctionId");
        returnObject["lots"] = this.lots;
        return returnObject;
      },
      initialize : function() {
        this.lots = new Lots;
      }
    });
    

    Please note in my example that rather than returning all attributes of the model, I’m just returning the attribute “auctionId.” This to me seemed safer because another developer here might later add attributes that do not need to be transported. That being said, it’s probably better practice to make an element of the returnObject contain all the attributes. This just made my re-building of the model on the client-side a little easier.

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

Sidebar

Related Questions

Sorry, this might be a basic/stupid/noob question - I am just trying to tweak
Just being very basic here. I'm trying to post an activeResource as Json and
this is a pretty basic question but I'm not entirely clear how to do
There may actually not be an answer to this question, but I wanted to
sorry i know this is a basic question, but i have been trying for
Probably it is a basic question, but could not found the answer anywhere in
Sorry for this basic question but my searches on this are not turning up
I have a really basic question concerning unix timestamp and mysql date. I'm trying
Question I'm trying to create a basic wxWidgets program with a text entry box,
Basic question so I feel dumb but..., Whats the proper syntax below in 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.