1. #1
    Ext User
    Join Date
    Jul 2007
    Vote Rating
    david.schoonover is on a distinguished road


    Default Extension: Remap MixedCollection Keys

    Extension: Remap MixedCollection Keys

    This isn't exactly a user-friendly extension, but it's a piece of generic code that I found useful.

    Problem: A user creates a new record client-side, which generates a temporary ID. Later, she uploads the record, and the client receives the record's permanent ID. Complexity, metadata, and processing are all reduced if I can always assume my database and the grid's store use the same IDs. Thus I'd want to update the ID for that record in the associated MixedCollection once it I know of its permanent ID.

    Solution: Place this code in a file or script block to run after ext-full.js and before you instantiate any MixedCollection objects which would use this functionality.

    • All grids use MixedCollection.
    • The extension is wrapped in Ext.onReady. Calls to this function appear to be executed in timestamp-order.
    • I've written these functions such that changing a key will NOT fire any update events.
    • This calls jQuery's version of Extend( intoThis, fromThis, [andThis, ...]). If you're not using jQuery, replace $.Extend with the appropriate substitute from your own library. I'm lazy.

    void MixedCollection.setKey( oldKey, newKey ): maps newKey as the key for the object presently keyed to oldKey.

    void MixedCollection.setKeyAt( idx, newKey ): maps newKey as the key for the object presently located at the idx-th index in the MixedCollection.

    void MixedCollection.setKeyFor( obj, newKey ): maps newKey as the key for obj.

    /* MixedCollection Update Keys API */
    $.extend( Ext.util.MixedCollection.prototype, {
    	setKey: function( oldKey, newKey ){ 
    		// We need to set these properties directly
    		// to avoid firing any "update" events.
    		// items
    		var record = this.map[oldKey];
    		record.id = newKey;
    		record.data.id = newKey;
    		// keys
    		var idx = this.keys.indexOf(oldKey);
    		this.keys[idx] = newKey;
    		// map
    		delete this.map[oldKey];
    		this.map[newKey] = record;
    	setKeyAt: function( idx, newKey ){
    		var oldKey = this.getKey(this.itemAt(idx));
    		return this.setKey(oldKey,newKey);
    	setKeyFor: function( obj, newKey ){
    		return this.setKey( this.getKey(obj), newKey );
    }); });
    I thought about adding similar functions to Ext.data.store... but really, if you need these functions to begin with, you're hacking at the source pretty deep already. I'm sure you can rouse yourself to type ds.data.setKey instead of ds.setKey.

    If you have any problems with this, let me know. It's been working fine with my app so far.

    Jack: Feel free to add this to the future of Ext if you so desire. (Though if you did, a link would be nice... but it's not like this was complicated.)
    Last edited by david.schoonover; 15 Jul 2007 at 2:07 AM. Reason: Typo, jQuery stuff.

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