Andy Moreno
Andy Moreno

Reputation: 25

How to load a single model in Sencha Touch 2?

I'm trying to load a model to add dirty data to the store, but can't seem to load up the actual model to then setData to it...

Doing this:

var model = Ext.ModelMgr.getModel("AT.model.Booking");

returns:

function () {
    return this.constructor.apply(this, arguments);
}

Which doesn't seem right at all. I found a thread about this; http://www.sencha.com/forum/showthread.php?177658-How-to-get-a-single-model

The following bug report states that it should be fixed in following versions but it doesn't seem to be... I'm not sure how to integrate the fix mentioned in the bug report...

Upvotes: 0

Views: 3125

Answers (3)

Subimage
Subimage

Reputation: 4491

This is how you load a single model.

var thing;
AT.model.Booking.load(thingId, {
  success: function(rec) { 
    thing = rec; 
  } 
});

A gotcha is that you have to have your proxy settings setup on your model in it's "config" section. This syntax is a little more straightforward than the whole "getmodel" thing.

Upvotes: 0

Gus
Gus

Reputation: 76

I'm not sure if this is what you want to accomplish but if you want to save a single record get the model off the DB and then call save().

var model = Ext.ModelManager.getModel('AT.model.Booking');

model.load(id, {
  scope: this,

  success: function(record) {
    if (profile.dirty) {
      profile.save();
    }
  },

  failure: function() {
    console.log('Something went wrong.');
  },
});

Upvotes: 1

Jay
Jay

Reputation: 3531

Correct me if I'm wrong but the argument to pass to the getModel method is the id of the model you want to get. You seem to be passing it the class name of a model.

Unless AT.model.Booking is an id for an actual model instance. Which seems weird to me but it's none of my business then :P

Upvotes: 0

Related Questions