Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Bug: batchNum of undefined observe.js ln:320

$
0
0
Without actually debugging code, I think the problem is that you are deleting a property of an Observe without telling the Observe that the property is no longer there.

removeAttr() will do this for you:
  1. order.removeAttr('genius_general')
It could also be that you are passing Observables into functions that are expecting Objects (more on this below):

Couple other things that I see:

1) You shouldn't be calling model() directly if you can help it and in your case you don't need it. model() takes a JSON response and creates an instance of the Model, which is done when findAll or findOne are called.

2) Your code is actually creating a model instance twice. First you call model() and then pass this instance to new Manager.Models.Order(...). You just need to use new Manager.Models.Order(...) and that way you also satisfy my first point :)

3) The variable order seems to be an Observe already. if it is just a regular Observe then you should be calling Manager.Models.Order(...) with the Object represented by the Observe, not the Observe itself. If order is already a model instance, then why are you using new Manager.Models.Order(...) at all? You can just use removeAttr, then update the status and save the model instance.

To extract the object that an Observe is observing, use attr() with no parameters like this:
  1. order.attr()
4) If you don't ever want the 'genius_general' object to be present in your model instances, you could override the model function so that it deletes it before turning it into an instance:

  1. can.Model({
  2.       ...
  3.       model: function(data){
  4.             delete data['genius_general'];
  5.             return can.Model.model.call(this, data);
  6.       }
  7. }, {})
      


Viewing all articles
Browse latest Browse all 3491

Trending Articles