X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..f5240829880f87e0cf581c6a296e436fdef0ef80:/src/data/Record.js?ds=sidebyside diff --git a/src/data/Record.js b/src/data/Record.js index ae95e4f8..f80bc853 100644 --- a/src/data/Record.js +++ b/src/data/Record.js @@ -1,6 +1,6 @@ /*! - * Ext JS Library 3.0.0 - * Copyright(c) 2006-2009 Ext JS, LLC + * Ext JS Library 3.3.0 + * Copyright(c) 2006-2010 Ext JS, Inc. * licensing@extjs.com * http://www.extjs.com/license */ @@ -21,15 +21,17 @@ * {@link #data} and {@link #id} properties.

*

Record objects generated by this constructor inherit all the methods of Ext.data.Record listed below.

* @constructor - * This constructor should not be used to create Record objects. Instead, use {@link #create} to - * generate a subclass of Ext.data.Record configured with information about its constituent fields. + *

This constructor should not be used to create Record objects. Instead, use {@link #create} to + * generate a subclass of Ext.data.Record configured with information about its constituent fields.

+ *

The generated constructor has the same signature as this constructor.

* @param {Object} data (Optional) An object, the properties of which provide values for the new Record's * fields. If not specified the {@link Ext.data.Field#defaultValue defaultValue} * for each field will be assigned. - * @param {Object} id (Optional) The id of the Record. This id should be unique, and is used by the - * {@link Ext.data.Store} object which owns the Record to index its collection of Records. If - * an id is not specified a {@link #phantom} Record will be created - * with an {@link #Record.id automatically generated id}. + * @param {Object} id (Optional) The id of the Record. The id is used by the + * {@link Ext.data.Store} object which owns the Record to index its collection + * of Records (therefore this id should be unique within each store). If an + * id is not specified a {@link #phantom} + * Record will be created with an {@link #Record.id automatically generated id}. */ Ext.data.Record = function(data, id){ // if no id, call the auto id method @@ -72,8 +74,8 @@ var myNewRecord = new TopicRecord( myStore.{@link Ext.data.Store#add add}(myNewRecord); * @method create - * @return {function} A constructor which is used to create new Records according - * to the definition. The constructor has the same signature as {@link #Ext.data.Record}. + * @return {Function} A constructor which is used to create new Records according + * to the definition. The constructor has the same signature as {@link #Record}. * @static */ Ext.data.Record.create = function(o){ @@ -135,22 +137,34 @@ Ext.data.Record.prototype = { * @property id * @type {Object} */ + /** + *

Only present if this Record was created by an {@link Ext.data.XmlReader XmlReader}.

+ *

The XML element which was the source of the data for this Record.

+ * @property node + * @type {XMLElement} + */ + /** + *

Only present if this Record was created by an {@link Ext.data.ArrayReader ArrayReader} or a {@link Ext.data.JsonReader JsonReader}.

+ *

The Array or object which was the source of the data for this Record.

+ * @property json + * @type {Array|Object} + */ /** * Readonly flag - true if this Record has been modified. * @type Boolean */ dirty : false, editing : false, - error: null, + error : null, /** * This object contains a key and value storing the original values of all modified * fields or is null if no fields have been modified. * @property modified * @type {Object} */ - modified: null, + modified : null, /** - * false when the record does not yet exist in a server-side database (see + * true when the record does not yet exist in a server-side database (see * {@link #markDirty}). Any record which has a real database pk set as its id property * is NOT a phantom -- it's real. * @property phantom @@ -188,7 +202,7 @@ rec.{@link #commit}(); // update the record in the store, bypass setting dirty flag, // and do not store the change in the {@link Ext.data.Store#getModifiedRecords modified records} -rec.{@link #data}['firstname'] = 'Wilma'); // updates record, but not the view +rec.{@link #data}['firstname'] = 'Wilma'; // updates record, but not the view rec.{@link #commit}(); // updates the view * * Notes:
* @param {String} name The {@link Ext.data.Field#name name of the field} to set. - * @param {Object} value The value to set the field to. + * @param {String/Object/Array} value The value to set the field to. */ set : function(name, value){ - var isObj = (typeof value === 'object'); - if(!isObj && String(this.data[name]) === String(value)){ - return; - } else if (isObj && Ext.encode(this.data[name]) === Ext.encode(value)) { + var encode = Ext.isPrimitive(value) ? String : Ext.encode; + if(encode(this.data[name]) == encode(value)) { return; - } + } this.dirty = true; if(!this.modified){ this.modified = {}; } - if(typeof this.modified[name] == 'undefined'){ + if(this.modified[name] === undefined){ this.modified[name] = this.data[name]; } this.data[name] = value; @@ -223,21 +235,21 @@ rec.{@link #commit}(); // updates the view }, // private - afterEdit: function(){ - if(this.store){ + afterEdit : function(){ + if (this.store != undefined && typeof this.store.afterEdit == "function") { this.store.afterEdit(this); } }, // private - afterReject: function(){ + afterReject : function(){ if(this.store){ this.store.afterReject(this); } }, // private - afterCommit: function(){ + afterCommit : function(){ if(this.store){ this.store.afterCommit(this); } @@ -347,10 +359,13 @@ rec.{@link #commit}(); // updates the view }, /** - * Creates a copy of this Record. - * @param {String} id (optional) A new Record id, defaults to {@link #Record.id autogenerating an id}. - * Note: if an id is not specified the copy created will be a - * {@link #phantom} Record. + * Creates a copy (clone) of this Record. + * @param {String} id (optional) A new Record id, defaults to the id + * of the record being copied. See {@link #id}. + * To generate a phantom record with a new id use:

+var rec = record.copy(); // clone the record
+Ext.data.Record.id(rec); // automatically generate a unique sequential id
+     * 
* @return {Record} */ copy : function(newId) { @@ -397,4 +412,4 @@ rec.{@link #commit}(); // updates the view this.modified[f.name] = this.data[f.name]; },this); } -}; \ No newline at end of file +};