Created
November 2, 2011 19:51
-
-
Save ppcano/1334693 to your computer and use it in GitHub Desktop.
SC2: how can notify array was modified on a elegant way?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CustomArrayController = SC.ArrayController.extend({ | |
content: null, | |
sortedContent:null, | |
_orderContent: function() { | |
var content = get(this, 'content'); | |
if ( content ) { | |
var result = SC.copy( content ); | |
result = result.sort( function( a, b ) { | |
return a.get('position') - b.get('position'); | |
}); | |
var currentSortedContent = get(this, 'sortedContent') | |
if (!currentSortedContent) currentSortedContent = []; | |
var i=0 | |
, currentMax = currentSortedContent.length | |
, max = result.length; | |
for ( i=0; i<currentMax; i++) { | |
currentSortedContent.popObject(); | |
} | |
for ( i=0; i<max; i++) { | |
currentSortedContent.pushObject( result[i] ); | |
} | |
set(this, 'sortedContent', currentSortedContent ); | |
// TODO | |
// notifyWillChange | |
// set(this, 'sortedContent', result ); | |
// notifyDidChange | |
} | |
}.observes('@each.position') | |
}); |
see how can fit: array.notifyPropertyChange('[]') ----> stilll pending
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
looking for a optimal way, something like the TODO comment should be required)