Last active
December 14, 2015 10:49
-
-
Save johncblandii/5074660 to your computer and use it in GitHub Desktop.
Add a view at a specific position in a list. Original inspiration: https://gist.github.com/iskugor/1485751.
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
Alloy.Globals.insertViewAt = function(parent, element, index) { | |
var children = parent.children.slice(0); | |
for(var i = 0; i < children.length; ++i){ | |
parent.remove(children[i]); | |
} | |
if(index >= 0) { | |
var tmp = children.slice(0, index); | |
tmp.push(element); | |
children = tmp.concat(children.slice(index)); | |
} | |
for (i = 0; i < children.length; ++i) { | |
parent.add(children[i]); | |
} | |
} | |
/** | |
* Usage: | |
* var view = Ti.UI.createView({backgroundColor: "red"}); | |
* Alloy.Globals.insertViewAt($.list, view, 1); //where '$.list' is a view in your alloy XML | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: This is not setup to be failure proof (passing a bad index may be problematic) but when used properly it will work just fine.