Obscure with Sencha Touch

(warning – techy talk follows)

Sencha Touch has great examples, samples and sales material. It’s not quite so shiny when you start combining samples and doing something semi- or properly serious. The various cases that the loose language allows don’t always, perhaps even rarely, work as might be expected. The flip-side of this is that there’s probably some value in having gained insight into how the code works (it’s great not having a black box to look at) and learning some of the idiosyncrasies.

The latest challenge has been looking at how hasMany (Ext.data.association.HasMany) cases are handled. These are handled with specialised use of Sencha’s Store object (Ext.data.Store). The ordinary use has code that detects existing records and discards them carefully taking into account ones that will be replaced. When it comes to hasMany this sophistication is missed. Maybe there is a reason for that but for me it meant that I was seeing the hasMany items for a record being duplicated each time I viewed the record. If Sencha ran my bank account then I wouldn’t mind payments-in as a hasMany on my account.

The answer seems to be to call removeAll() on the hasMany item’s data store i.e. in a beforeload listener function on the store that uses a model with a hasMany:

listeners: {
beforeload: function(operation) {
for(var i=0; i<this.data.all.length; i++) {
if (this.data.all[i].hasManyStore)
this.data.all[i].hasManyStore.removeAll();
}
}
}

Advertisements

2 Comments

Filed under Uncategorized

2 responses to “Obscure with Sencha Touch

  1. Masud

    I can’t thank you enough for this, I was searching for this everywhere and have found the solution, thanks to this post. Reminds me of why I have such a strong love/hate relationship with Sencha.

  2. Pingback: Sencha Touch 2.3, hasMany association, and duplication of store entries – Masud Khokhar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s