1. #1
    Sencha User chuckoh's Avatar
    Join Date
    Jan 2012
    Location
    Seoul, Korea
    Posts
    16
    Answers
    1
    Vote Rating
    0
    chuckoh is on a distinguished road

      0  

    Default Answered: Where's the best place to pre-process the data records?

    Answered: Where's the best place to pre-process the data records?


    I have a Ext.List to load 1000s of data records and list them. They are basically comments. And, I'd like to detect some random spams that I can pre-process with a set of regular expressions.

    In my controller,

    Code:
        init: function() {
            var commentStore = Ext.getStore('Comments') || Ext.create('Comments');
            commentStore.on({
                scope: this,
                load: 'onCommentStoreLoad'
            });
        },
        onCommentStoreLoad: function(store, records, successful) {
            if (successful) {
                // I tried to reformat the record data with the following line but, it didn't work
                // (note that I removed the actual detection part for clarity.)
                for (var i = 0; i < records.length; i++) {
                    records[i].getData().comment = '[spam] '+records[i].getData().comment;
                }
                var comment_list = this.getCommentList();
                comment_list.setData(records);
            }
        }
    Since the above didn't work, I moved the detection part to my View like this.

    Code:
           {
                xtype: 'list',
                id: 'comment-list',
                store: 'Comments',
                itemTpl: commentTemplate,
                prepareData: function(data) {
                    data.comment = '[spam]'+data.comment;
                    return data;
                }
            }]
    This should work. But, I am not quite happy with putting some logics into my View.

    So, where is the best place to put this detection logic with MVC programming style?
    I am curious...

    Thank you for reading. =)

  2. I would personally put the preprocessor for the comment field in your Model definition. You could do this like this:

    Code:
    Ext.define('MyApp.model.Comment', {
        extend: 'Ext.data.Model,
        config: {
            fields: [{
                name: 'comment', 
                type: 'string', 
                convert: function(value, record) {
                    return '[spam] ' + value;
                }
            }]
        }
    });
    Look for more information in the docs

  3. #2
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Answers
    28
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    I would personally put the preprocessor for the comment field in your Model definition. You could do this like this:

    Code:
    Ext.define('MyApp.model.Comment', {
        extend: 'Ext.data.Model,
        config: {
            fields: [{
                name: 'comment', 
                type: 'string', 
                convert: function(value, record) {
                    return '[spam] ' + value;
                }
            }]
        }
    });
    Look for more information in the docs

  4. #3
    Sencha User chuckoh's Avatar
    Join Date
    Jan 2012
    Location
    Seoul, Korea
    Posts
    16
    Answers
    1
    Vote Rating
    0
    chuckoh is on a distinguished road

      0  

    Default


    Thank you so much!

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