1. #1
    Sencha User
    Join Date
    Mar 2010
    Posts
    49
    Answers
    2
    Vote Rating
    0
    chaddjohnson is on a distinguished road

      0  

    Default Answered: model.convert() not called when accessing field via model.get()

    Answered: model.convert() not called when accessing field via model.get()


    I have the following model:
    Code:
    (function() {
    
      var fourDecimals = function(value, record) {
        return parseFloat(value.toFixed(4));
      }
      
      Ext.define('App.model.Stock', {
        extend: 'Ext.data.Model',
        fields: [
          {name: 'Symbol',             type: 'string'},
          {name: 'TradePrice',         type: 'float'},
          {name: 'Bid',                type: 'float'},
          {name: 'Ask',                type: 'float'},
          {name: 'Volume',             type: 'int'},
          {name: 'TodaysClose',        type: 'float'},
          {name: 'PreviousClose',      type: 'float'},
          {
            name: 'PriceChange',
            type: 'float',
            convert: function(value, record) {
              return parseFloat((record.get('TradePrice') - record.get('PreviousClose')).toFixed(4));
            }
          },{
            name: 'PercentPriceChange',
            type: 'float',
            convert: function(value, record) {
              return parseFloat((((record.get('TradePrice') / record.get('PreviousClose')) - 1) * 100).toFixed(2));
            }
          }
        ]
      });
    
    })();
    When I call do the following, the convert() function is not called for my model instance:

    Code:
    model.set('TradePrice', 12.34);
    var priceChange = model.get('PriceChange');
    Is this a bug?

  2. This does work in Sencha Touch 2. When a field that a convert() function depends on is updated, the convert() function is called.

    I found a workaround based on this blog post:

    Code:
    set: function(fieldName, newValue) {
      this.callParent(arguments);
    
      // Force recalculation of dependent fields.
      if (typeof fieldName == 'object' || fieldName == 'TradePrice' || fieldName == 'PreviousClose') {
        this.set('PriceChange');
        this.set('PercentPriceChange');
      }
    }
    I added that to the model.

  3. #2
    Sencha User
    Join Date
    Mar 2010
    Posts
    49
    Answers
    2
    Vote Rating
    0
    chaddjohnson is on a distinguished road

      0  

    Default


    This does work in Sencha Touch 2. When a field that a convert() function depends on is updated, the convert() function is called.

    I found a workaround based on this blog post:

    Code:
    set: function(fieldName, newValue) {
      this.callParent(arguments);
    
      // Force recalculation of dependent fields.
      if (typeof fieldName == 'object' || fieldName == 'TradePrice' || fieldName == 'PreviousClose') {
        this.set('PriceChange');
        this.set('PercentPriceChange');
      }
    }
    I added that to the model.

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..."