X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/3789b528d8dd8aad4558e38e22d775bcab1cbd36..6746dc89c47ed01b165cc1152533605f97eb8e8d:/docs/output/Ext.data.Field.js diff --git a/docs/output/Ext.data.Field.js b/docs/output/Ext.data.Field.js index 30830ef6..3a82d484 100644 --- a/docs/output/Ext.data.Field.js +++ b/docs/output/Ext.data.Field.js @@ -1,180 +1,229 @@ Ext.data.JsonP.Ext_data_Field({ - "tagname": "class", - "name": "Ext.data.Field", - "doc": "

Fields are used to define what a Model is. They aren't instantiated directly - instead, when we create a class \nthat extends Ext.data.Model, it will automatically create a Field instance for each field configured in a \nModel. For example, we might set up a model like this:

\n\n\n\n\n
Ext.define('User', {\n    extend: 'Ext.data.Model',\n    fields: [\n        'name', 'email',\n        {name: 'age', type: 'int'},\n        {name: 'gender', type: 'string', defaultValue: 'Unknown'}\n    ]\n});\n
\n\n\n\n\n

Four fields will have been created for the User Model - name, email, age and gender. Note that we specified a\ncouple of different formats here; if we only pass in the string name of the field (as with name and email), the\nfield is set up with the 'auto' type. It's as if we'd done this instead:

\n\n\n\n\n
Ext.define('User', {\n    extend: 'Ext.data.Model',\n    fields: [\n        {name: 'name', type: 'auto'},\n        {name: 'email', type: 'auto'},\n        {name: 'age', type: 'int'},\n        {name: 'gender', type: 'string', defaultValue: 'Unknown'}\n    ]\n});\n
\n\n\n\n\n

Types and conversion

\n\n\n\n\n

The type is important - it's used to automatically convert data passed to the field into the correct\nformat. In our example above, the name and email fields used the 'auto' type and will just accept anything that is\npassed into them. The 'age' field had an 'int' type however, so if we passed 25.4 this would be rounded to 25.

\n\n\n\n\n

Sometimes a simple type isn't enough, or we want to perform some processing when we load a Field's data. We can\ndo this using a convert function. Here, we're going to create a new field based on another:

\n\n\n

\n\n
Ext.define('User', {\n    extend: 'Ext.data.Model',\n    fields: [\n        'name', 'email',\n        {name: 'age', type: 'int'},\n        {name: 'gender', type: 'string', defaultValue: 'Unknown'},\n\n        {\n            name: 'firstName',\n            convert: function(value, record) {\n                var fullName  = record.get('name'),\n                    splits    = fullName.split(\" \"),\n                    firstName = splits[0];\n\n                return firstName;\n            }\n        }\n    ]\n});\n
\n\n\n\n\n

Now when we create a new User, the firstName is populated automatically based on the name:

\n\n\n

\n\n
var ed = Ext.ModelManager.create({name: 'Ed Spencer'}, 'User');\n\nconsole.log(ed.get('firstName')); //logs 'Ed', based on our convert function\n
\n\n\n\n\n

In fact, if we log out all of the data inside ed, we'll see this:

\n\n\n

\n\n
console.log(ed.data);\n\n//outputs this:\n{\n    age: 0,\n    email: \"\",\n    firstName: \"Ed\",\n    gender: \"Unknown\",\n    name: \"Ed Spencer\"\n}\n
\n\n\n\n\n

The age field has been given a default of zero because we made it an int type. As an auto field, email has\ndefaulted to an empty string. When we registered the User model we set gender's defaultValue to 'Unknown'\nso we see that now. Let's correct that and satisfy ourselves that the types work as we expect:

\n\n\n

\n\n
ed.set('gender', 'Male');\ned.get('gender'); //returns 'Male'\n\ned.set('age', 25.4);\ned.get('age'); //returns 25 - we wanted an int, not a float, so no decimal places allowed\n
\n\n", - "extends": "Object", - "mixins": [ - - ], - "alternateClassNames": [ + "allMixins": [ ], - "xtype": null, - "author": "Ed Spencer", + "deprecated": null, "docauthor": null, - "singleton": false, - "private": false, - "cfg": [ - { - "tagname": "cfg", - "name": "convert", - "member": "Ext.data.Field", - "type": "Function", - "doc": "

(Optional) A function which converts the value provided by the Reader into an object that will be stored\nin the Model. It is passed the following parameters:

\n\n
// example of convert function\nfunction fullName(v, record){\n    return record.name.last + ', ' + record.name.first;\n}\n\nfunction location(v, record){\n    return !record.city ? '' : (record.city + ', ' + record.state);\n}\n\nExt.define('Dude', {\n    extend: 'Ext.data.Model',\n    fields: [\n        {name: 'fullname',  convert: fullName},\n        {name: 'firstname', mapping: 'name.first'},\n        {name: 'lastname',  mapping: 'name.last'},\n        {name: 'city', defaultValue: 'homeless'},\n        'state',\n        {name: 'location',  convert: location}\n    ]\n});\n\n// create the data store\nvar store = new Ext.data.Store({\n    reader: {\n        type: 'json',\n        model: 'Dude',\n        idProperty: 'key',\n        root: 'daRoot',\n        totalProperty: 'total'\n    }\n});\n\nvar myData = [\n    { key: 1,\n      name: { first: 'Fat',    last:  'Albert' }\n      // notice no city, state provided in data object\n    },\n    { key: 2,\n      name: { first: 'Barney', last:  'Rubble' },\n      city: 'Bedrock', state: 'Stoneridge'\n    },\n    { key: 3,\n      name: { first: 'Cliff',  last:  'Claven' },\n      city: 'Boston',  state: 'MA'\n    }\n];\n
\n\n", - "private": false, - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 162, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field-cfg-convert", - "shortDoc": "(Optional) A function which converts the value provided by the Reader into an object that will be stored\nin the Model..." - }, - { - "tagname": "cfg", - "name": "dateFormat", - "member": "Ext.data.Field", - "type": "String", - "doc": "

(Optional) Used when converting received data into a Date when the type is specified as \"date\".

\n\n\n

A format string for the Ext.Date.parse function, or \"timestamp\" if the\nvalue provided by the Reader is a UNIX timestamp, or \"time\" if the value provided by the Reader is a\njavascript millisecond timestamp. See Date

\n\n", - "private": false, - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 221, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field-cfg-dateFormat", - "shortDoc": "(Optional) Used when converting received data into a Date when the type is specified as \"date\".\n\n\nA format string for..." - }, - { - "tagname": "cfg", - "name": "defaultValue", - "member": "Ext.data.Field", - "type": "Mixed", - "doc": "

(Optional) The default value used when a Model is being created by a Reader\nwhen the item referenced by the mapping does not exist in the data\nobject (i.e. undefined). (defaults to \"\")

\n", - "private": false, - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 237, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field-cfg-defaultValue", - "shortDoc": "(Optional) The default value used when a Model is being created by a Reader\nwhen the item referenced by the mapping d..." - }, - { - "tagname": "cfg", - "name": "mapping", - "member": "Ext.data.Field", - "type": "String/Number", - "doc": "

(Optional) A path expression for use by the Ext.data.reader.Reader implementation\nthat is creating the Model to extract the Field value from the data object.\nIf the path expression is the same as the field name, the mapping may be omitted.

\n\n\n

The form of the mapping expression depends on the Reader being used.

\n\n\n
\n\n\n

If a more complex value extraction strategy is required, then configure the Field with a convert\nfunction. This is passed the whole row object, and may interrogate it in whatever way is necessary in order to\nreturn the desired data.

\n\n", - "private": false, - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 244, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field-cfg-mapping", - "shortDoc": "(Optional) A path expression for use by the Ext.data.reader.Reader implementation\nthat is creating the Model to extra..." - }, - { - "tagname": "cfg", - "name": "name", - "member": "Ext.data.Field", - "type": "String", - "doc": "

The name by which the field is referenced within the Model. This is referenced by, for example,\nthe dataIndex property in column definition objects passed to Ext.grid.property.HeaderContainer.

\n\n

Note: In the simplest case, if no properties other than name are required, a field\ndefinition may consist of just a String for the field name.

\n\n", - "private": false, - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 138, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field-cfg-name", - "shortDoc": "The name by which the field is referenced within the Model. This is referenced by, for example,\nthe dataIndex propert..." - }, - { - "tagname": "cfg", - "name": "persist", - "member": "Ext.data.Field", - "type": "Boolean", - "doc": "

False to exclude this field from the Ext.data.Model.modified fields in a model. This\nwill also exclude the field from being written using a Ext.data.writer.Writer. This option\nis useful when model fields are used to keep state on the client but do not need to be persisted\nto the server. Defaults to true.

\n", - "private": false, - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 301, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field-cfg-persist", - "shortDoc": "False to exclude this field from the Ext.data.Model.modified fields in a model. This\nwill also exclude the field from..." - }, - { - "tagname": "cfg", - "name": "sortDir", - "member": "Ext.data.Field", - "type": "String", - "doc": "

(Optional) Initial direction to sort (\"ASC\" or \"DESC\"). Defaults to\n\"ASC\".

\n", - "private": false, - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 286, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field-cfg-sortDir" - }, - { - "tagname": "cfg", - "name": "sortType", - "member": "Ext.data.Field", - "type": "Function", - "doc": "

(Optional) A function which converts a Field's value to a comparable value in order to ensure\ncorrect sort ordering. Predefined functions are provided in Ext.data.SortTypes. A custom\nsort example:

\n\n
// current sort     after sort we want\n// +-+------+          +-+------+\n// |1|First |          |1|First |\n// |2|Last  |          |3|Second|\n// |3|Second|          |2|Last  |\n// +-+------+          +-+------+\n\nsortType: function(value) {\n   switch (value.toLowerCase()) // native toLowerCase():\n   {\n      case 'first': return 1;\n      case 'second': return 2;\n      default: return 3;\n   }\n}\n
\n\n", - "private": false, - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 263, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field-cfg-sortType", - "shortDoc": "(Optional) A function which converts a Field's value to a comparable value in order to ensure\ncorrect sort ordering. ..." - }, - { - "tagname": "cfg", - "name": "type", - "member": "Ext.data.Field", - "type": "Mixed", - "doc": "

(Optional) The data type for automatic conversion from received data to the stored value if convert\nhas not been specified. This may be specified as a string value. Possible values are

\n\n
\n\n\n

This may also be specified by referencing a member of the Ext.data.Types class.

\n\n\n

Developers may create their own application-specific data types by defining new members of the\nExt.data.Types class.

\n\n", - "private": false, - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 146, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field-cfg-type", - "shortDoc": "(Optional) The data type for automatic conversion from received data to the stored value if convert\nhas not been spec..." - }, - { - "tagname": "cfg", - "name": "useNull", - "member": "Ext.data.Field", - "type": "Boolean", - "doc": "

(Optional) Use when converting received data into a Number type (either int or float). If the value cannot be parsed,\nnull will be used if useNull is true, otherwise the value will be 0. Defaults to false\n\n", - "private": false, - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 230, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field-cfg-useNull", - "shortDoc": "(Optional) Use when converting received data into a Number type (either int or float). If the value cannot be parsed,..." - } - ], - "method": [ + "members": { + "cfg": [ + { + "type": "Function", + "deprecated": null, + "alias": null, + "protected": false, + "tagname": "cfg", + "href": "Field3.html#Ext-data-Field-cfg-convert", + "shortDoc": "(Optional) A function which converts the value provided by the Reader into an object that will be stored\nin the Model. ...", + "static": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "name": "convert", + "owner": "Ext.data.Field", + "doc": "

(Optional) A function which converts the value provided by the Reader into an object that will be stored\nin the Model. It is passed the following parameters:

\n\n
// example of convert function\nfunction fullName(v, record){\n    return record.name.last + ', ' + record.name.first;\n}\n\nfunction location(v, record){\n    return !record.city ? '' : (record.city + ', ' + record.state);\n}\n\nExt.define('Dude', {\n    extend: 'Ext.data.Model',\n    fields: [\n        {name: 'fullname',  convert: fullName},\n        {name: 'firstname', mapping: 'name.first'},\n        {name: 'lastname',  mapping: 'name.last'},\n        {name: 'city', defaultValue: 'homeless'},\n        'state',\n        {name: 'location',  convert: location}\n    ]\n});\n\n// create the data store\nvar store = new Ext.data.Store({\n    reader: {\n        type: 'json',\n        model: 'Dude',\n        idProperty: 'key',\n        root: 'daRoot',\n        totalProperty: 'total'\n    }\n});\n\nvar myData = [\n    { key: 1,\n      name: { first: 'Fat',    last:  'Albert' }\n      // notice no city, state provided in data object\n    },\n    { key: 2,\n      name: { first: 'Barney', last:  'Rubble' },\n      city: 'Bedrock', state: 'Stoneridge'\n    },\n    { key: 3,\n      name: { first: 'Cliff',  last:  'Claven' },\n      city: 'Boston',  state: 'MA'\n    }\n];\n
\n\n", + "linenr": 162, + "html_filename": "Field3.html" + }, + { + "type": "String", + "deprecated": null, + "alias": null, + "protected": false, + "tagname": "cfg", + "href": "Field3.html#Ext-data-Field-cfg-dateFormat", + "shortDoc": "(Optional) Used when converting received data into a Date when the type is specified as \"date\". ...", + "static": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "name": "dateFormat", + "owner": "Ext.data.Field", + "doc": "

(Optional) Used when converting received data into a Date when the type is specified as \"date\".

\n\n\n

A format string for the Ext.Date.parse function, or \"timestamp\" if the\nvalue provided by the Reader is a UNIX timestamp, or \"time\" if the value provided by the Reader is a\njavascript millisecond timestamp. See Ext.Date

\n\n", + "linenr": 221, + "html_filename": "Field3.html" + }, + { + "type": "Mixed", + "deprecated": null, + "alias": null, + "protected": false, + "tagname": "cfg", + "href": "Field3.html#Ext-data-Field-cfg-defaultValue", + "shortDoc": "(Optional) The default value used when a Model is being created by a Reader\nwhen the item referenced by the mapping d...", + "static": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "name": "defaultValue", + "owner": "Ext.data.Field", + "doc": "

(Optional) The default value used when a Model is being created by a Reader\nwhen the item referenced by the mapping does not exist in the data\nobject (i.e. undefined). (defaults to \"\")

\n", + "linenr": 237, + "html_filename": "Field3.html" + }, + { + "type": "String/Number", + "deprecated": null, + "alias": null, + "protected": false, + "tagname": "cfg", + "href": "Field3.html#Ext-data-Field-cfg-mapping", + "shortDoc": "(Optional) A path expression for use by the Ext.data.reader.Reader implementation\nthat is creating the Model to extra...", + "static": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "name": "mapping", + "owner": "Ext.data.Field", + "doc": "

(Optional) A path expression for use by the Ext.data.reader.Reader implementation\nthat is creating the Model to extract the Field value from the data object.\nIf the path expression is the same as the field name, the mapping may be omitted.

\n\n\n

The form of the mapping expression depends on the Reader being used.

\n\n\n
\n\n\n

If a more complex value extraction strategy is required, then configure the Field with a convert\nfunction. This is passed the whole row object, and may interrogate it in whatever way is necessary in order to\nreturn the desired data.

\n\n", + "linenr": 244, + "html_filename": "Field3.html" + }, + { + "type": "String", + "deprecated": null, + "alias": null, + "protected": false, + "tagname": "cfg", + "href": "Field3.html#Ext-data-Field-cfg-name", + "shortDoc": "The name by which the field is referenced within the Model. ...", + "static": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "name": "name", + "owner": "Ext.data.Field", + "doc": "

The name by which the field is referenced within the Model. This is referenced by, for example,\nthe dataIndex property in column definition objects passed to Ext.grid.property.HeaderContainer.

\n\n

Note: In the simplest case, if no properties other than name are required, a field\ndefinition may consist of just a String for the field name.

\n\n", + "linenr": 138, + "html_filename": "Field3.html" + }, + { + "type": "Boolean", + "deprecated": null, + "alias": null, + "protected": false, + "tagname": "cfg", + "href": "Field3.html#Ext-data-Field-cfg-persist", + "shortDoc": "False to exclude this field from the Ext.data.Model.modified fields in a model. ...", + "static": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "name": "persist", + "owner": "Ext.data.Field", + "doc": "

False to exclude this field from the Ext.data.Model.modified fields in a model. This\nwill also exclude the field from being written using a Ext.data.writer.Writer. This option\nis useful when model fields are used to keep state on the client but do not need to be persisted\nto the server. Defaults to true.

\n", + "linenr": 301, + "html_filename": "Field3.html" + }, + { + "type": "String", + "deprecated": null, + "alias": null, + "protected": false, + "tagname": "cfg", + "href": "Field3.html#Ext-data-Field-cfg-sortDir", + "shortDoc": "(Optional) Initial direction to sort (\"ASC\" or \"DESC\"). ...", + "static": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "name": "sortDir", + "owner": "Ext.data.Field", + "doc": "

(Optional) Initial direction to sort (\"ASC\" or \"DESC\"). Defaults to\n\"ASC\".

\n", + "linenr": 286, + "html_filename": "Field3.html" + }, + { + "type": "Function", + "deprecated": null, + "alias": null, + "protected": false, + "tagname": "cfg", + "href": "Field3.html#Ext-data-Field-cfg-sortType", + "shortDoc": "(Optional) A function which converts a Field's value to a comparable value in order to ensure\ncorrect sort ordering. ...", + "static": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "name": "sortType", + "owner": "Ext.data.Field", + "doc": "

(Optional) A function which converts a Field's value to a comparable value in order to ensure\ncorrect sort ordering. Predefined functions are provided in Ext.data.SortTypes. A custom\nsort example:

\n\n
// current sort     after sort we want\n// +-+------+          +-+------+\n// |1|First |          |1|First |\n// |2|Last  |          |3|Second|\n// |3|Second|          |2|Last  |\n// +-+------+          +-+------+\n\nsortType: function(value) {\n   switch (value.toLowerCase()) // native toLowerCase():\n   {\n      case 'first': return 1;\n      case 'second': return 2;\n      default: return 3;\n   }\n}\n
\n\n", + "linenr": 263, + "html_filename": "Field3.html" + }, + { + "type": "Mixed", + "deprecated": null, + "alias": null, + "protected": false, + "tagname": "cfg", + "href": "Field3.html#Ext-data-Field-cfg-type", + "shortDoc": "(Optional) The data type for automatic conversion from received data to the stored value if convert\nhas not been spec...", + "static": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "name": "type", + "owner": "Ext.data.Field", + "doc": "

(Optional) The data type for automatic conversion from received data to the stored value if convert\nhas not been specified. This may be specified as a string value. Possible values are

\n\n
\n\n\n

This may also be specified by referencing a member of the Ext.data.Types class.

\n\n\n

Developers may create their own application-specific data types by defining new members of the\nExt.data.Types class.

\n\n", + "linenr": 146, + "html_filename": "Field3.html" + }, + { + "type": "Boolean", + "deprecated": null, + "alias": null, + "protected": false, + "tagname": "cfg", + "href": "Field3.html#Ext-data-Field-cfg-useNull", + "shortDoc": "(Optional) Use when converting received data into a Number type (either int or float). ...", + "static": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "name": "useNull", + "owner": "Ext.data.Field", + "doc": "

(Optional) Use when converting received data into a Number type (either int or float). If the value cannot be parsed,\nnull will be used if useNull is true, otherwise the value will be 0. Defaults to false\n\n", + "linenr": 230, + "html_filename": "Field3.html" + } + ], + "method": [ - ], - "property": [ + ], + "property": [ - ], - "event": [ + ], + "cssVar": [ - ], - "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Field.js", - "linenr": 1, - "html_filename": "Field3.html", - "href": "Field3.html#Ext-data-Field", - "cssVar": [ + ], + "cssMixin": [ - ], - "cssMixin": [ + ], + "event": [ - ], - "component": false, + ] + }, + "singleton": false, + "alias": null, "superclasses": [ ], + "protected": false, + "tagname": "class", + "mixins": [ + + ], + "href": "Field3.html#Ext-data-Field", "subclasses": [ ], + "static": false, + "author": "Ed Spencer", + "component": false, + "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Field.js", + "private": false, + "alternateClassNames": [ + + ], + "name": "Ext.data.Field", + "doc": "

Fields are used to define what a Model is. They aren't instantiated directly - instead, when we create a class \nthat extends Ext.data.Model, it will automatically create a Field instance for each field configured in a \nModel. For example, we might set up a model like this:

\n\n\n\n\n
Ext.define('User', {\n    extend: 'Ext.data.Model',\n    fields: [\n        'name', 'email',\n        {name: 'age', type: 'int'},\n        {name: 'gender', type: 'string', defaultValue: 'Unknown'}\n    ]\n});\n
\n\n\n\n\n

Four fields will have been created for the User Model - name, email, age and gender. Note that we specified a\ncouple of different formats here; if we only pass in the string name of the field (as with name and email), the\nfield is set up with the 'auto' type. It's as if we'd done this instead:

\n\n\n\n\n
Ext.define('User', {\n    extend: 'Ext.data.Model',\n    fields: [\n        {name: 'name', type: 'auto'},\n        {name: 'email', type: 'auto'},\n        {name: 'age', type: 'int'},\n        {name: 'gender', type: 'string', defaultValue: 'Unknown'}\n    ]\n});\n
\n\n\n\n\n

Types and conversion

\n\n\n\n\n

The type is important - it's used to automatically convert data passed to the field into the correct\nformat. In our example above, the name and email fields used the 'auto' type and will just accept anything that is\npassed into them. The 'age' field had an 'int' type however, so if we passed 25.4 this would be rounded to 25.

\n\n\n\n\n

Sometimes a simple type isn't enough, or we want to perform some processing when we load a Field's data. We can\ndo this using a convert function. Here, we're going to create a new field based on another:

\n\n\n

\n\n
Ext.define('User', {\n    extend: 'Ext.data.Model',\n    fields: [\n        'name', 'email',\n        {name: 'age', type: 'int'},\n        {name: 'gender', type: 'string', defaultValue: 'Unknown'},\n\n        {\n            name: 'firstName',\n            convert: function(value, record) {\n                var fullName  = record.get('name'),\n                    splits    = fullName.split(\" \"),\n                    firstName = splits[0];\n\n                return firstName;\n            }\n        }\n    ]\n});\n
\n\n\n\n\n

Now when we create a new User, the firstName is populated automatically based on the name:

\n\n\n

\n\n
var ed = Ext.ModelManager.create({name: 'Ed Spencer'}, 'User');\n\nconsole.log(ed.get('firstName')); //logs 'Ed', based on our convert function\n
\n\n\n\n\n

In fact, if we log out all of the data inside ed, we'll see this:

\n\n\n

\n\n
console.log(ed.data);\n\n//outputs this:\n{\n    age: 0,\n    email: \"\",\n    firstName: \"Ed\",\n    gender: \"Unknown\",\n    name: \"Ed Spencer\"\n}\n
\n\n\n\n\n

The age field has been given a default of zero because we made it an int type. As an auto field, email has\ndefaulted to an empty string. When we registered the User model we set gender's defaultValue to 'Unknown'\nso we see that now. Let's correct that and satisfy ourselves that the types work as we expect:

\n\n\n

\n\n
ed.set('gender', 'Male');\ned.get('gender'); //returns 'Male'\n\ned.set('age', 25.4);\ned.get('age'); //returns 25 - we wanted an int, not a float, so no decimal places allowed\n
\n\n", "mixedInto": [ ], - "allMixins": [ + "linenr": 1, + "xtypes": [ - ] + ], + "html_filename": "Field3.html", + "extends": "Object" }); \ No newline at end of file