/ Published in: JavaScript
It’s pretty straightforward, we loop the existing Views of the ScrollableView and copy each View, replacing the one to be change, to a new array. Then we tell the ScrollableView to use our new Views-array for it’s Views.
I hope this helps someone.
I hope this helps someone.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Replace (update) one view of a ScrollablView with a new one * * @param object The scrollableView * @param object The old view to be replaced * @param object The new view to replace the old one * @return void */ function replaceView(scrollableView, oldView, newView) { // loop all the views in the scrollable view for (var i = 0, newViews = [], l = scrollableView.views.length; i < l; i++) { // replace the old view with the new one if (i == scrollableView.currentPage) newViews.push(newView); // leave the other views unchanged else newViews.push(scrollableView.views[i]); } // update the scrollableView's views array with the new one scrollableView.views = newViews; }