Search code examples
sencha-touch-2

How do you get field properties


I'm working on a Sencha app and having trouble accessing the fields of a basic model that I've defined. I use Ext.define to define a model and Ext.create to create an instance of it. According to the docs I should be able to access its fields by calling get.(<fieldname>) on the field, but it's not working and it's returning null. Here's the basic code, along with a jsfiddle.

Ext.define('App.model.Patient', {
    extend: 'Ext.data.Model',
    config: {
        fields: ['admissionGuid',
            'firstName', 'middleInitial', 'lastName', 'visitType',
            { name: "visitDate", type: 'date'}]
    }
});​


var newVisit = Ext.create('App.model.Patient', {
        admissionGuid: 1234,
        firstName: "FirstName",
        middleName: "MiddleName",
        lastName: "LastName",
        visitType: "Revisit",
        visitDate: new Date() 
});

alert(newVisit.get('admissionGuid')); // returns null

Solution

  • Your code is correct using Sencha Touch 2. I've tested it, and it works as expected. Fiddle here using ST: http://www.senchafiddle.com/#6Q9ac

    ExtJS and Sencha Touch share similar class systems, but they are not identical.