0

I have an application where my model data has the idProperty set to '_id' as per server mongodb data. If I try to load a model instance by given id I get this strange error: Cannot call method 'hasId' of undefined

My model is defined as follows:

Ext.define 'heroico.model.Visitor',
    extend: 'Ext.data.Model'
    fields: [...]
    idProperty: '_id'
    proxy:
        type: 'memory'

And I'm just hitting heroico.model.Visitor.load('FcFaNkhH9TJzQ57D5') in my chrome console where FcFaNkhH9TJzQ57D5 is an actual id present in the store. Any ideas?

Extjs version 4.2.1

Romeo Mihalcea
  • 9,714
  • 12
  • 50
  • 102

1 Answers1

0

If you want to get object from store by id, you need to get it FROM STORE!

You need to create store with model: "heroico.model.Visitor" and after that do

var myVisitor = visitorsStore.getById("your_hard_id")

and you get visitor object, based in heroico.model.Visitor model.

If you need to load data from server by static load method, you need to set URL in model's proxy config. Sample:

Ext.define "heroico.model.Visitort",
  extend: "Ext.data.Model"
  fields: [..]
  idProperty: "_id"
  proxy:
    type: "rest"
    url: "/your/url/for_data_load"