1. #1
    Sencha User
    Join Date
    Jul 2012
    Location
    Italy
    Posts
    84
    Answers
    1
    Vote Rating
    4
    Tegola is on a distinguished road

      0  

    Default Answered: Default value for date fields

    Answered: Default value for date fields


    Hello,
    What's the best way to add the current date to a record field?

    Here's is what was my initial guess:
    Code:
    Ext.define('Message', {
    	extend: 'Ext.data.Model',
    	config: {
    		fields: [
    			{ name: 'id', type: 'int' },
    			{ name: 'title', type: 'string' },
    			{ name: 'body', type: 'string' },
    			{ name: 'created-at', type: 'date', dateFormat: 'Y-m-d H:i:s', defaultValue: new Date() }
    		]
    	}
    });
    However, "new Date()" picks the date when the Model class is instantiated. I would it to pick the date when I do a Ext.create('Message').

    I know I could just do:
    Code:
    Ext.create('Message', { 'created-at': new Date() })
    But I was searching for a way to make sencha do this automatically.

    Thanks

  2. Code:
    constructor:function(){
            var data = arguments[0]||{};
    
    
            data['created-at'] = new Date();
    
            if(arguments.length===0){
                this.callParent([data]);
            }else{
               this.callParent(arguments);
            } 
    }

  3. #2
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    Code:
    constructor:function(){
            var data = arguments[0]||{};
    
    
            data['created-at'] = new Date();
    
            if(arguments.length===0){
                this.callParent([data]);
            }else{
               this.callParent(arguments);
            } 
    }
    I write English by translator.

  4. #3
    Sencha User
    Join Date
    Jul 2012
    Location
    Italy
    Posts
    84
    Answers
    1
    Vote Rating
    4
    Tegola is on a distinguished road

      0  

    Default


    Thanks!

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi