daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jan 16th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [
  2.     {id: 1, title="test 1"},
  3.     {id: 2, title="test 2"},
  4.     {id: 3, title="test 3"},
  5.     {id: 4, title="test 4"},
  6.     {id: 5, title="test 5"},
  7.     {id: 6, title="test 6"}
  8. ]
  9.    
  10. <div id="myContainer">
  11.     <div class="row-fluid">
  12.         <div class="span4">test 1</div>
  13.         <div class="span4">test 2</div>
  14.         <div class="span4">test 3</div>
  15.     </div>
  16.     <div class="row-fluid">
  17.         <div class="span4">test 4</div>
  18.         <div class="span4">test 5</div>
  19.         <div class="span4">test 6</div>
  20.     </div>
  21. </div>
  22.    
  23. appendHtml: function(compositeView, itemView, index){
  24.     ...
  25.     if ((index % 3) === 0  || lastelement){
  26.         ... append
  27.     }
  28. }
  29.    
  30. this.cacheColumns.push(itemView.el);
  31.  
  32.  
  33.  
  34.                     // If current index (+1) has rest of 0 when we devide it by column amount
  35.  
  36.                     // OR
  37.  
  38.                     // End of array loop.
  39.  
  40.                     if (((index+1) % this.colAmount) === 0 || index == this.collection.length-1){
  41.  
  42.                             var row = $('<div class="row-fluid" />');
  43.  
  44.                             for(var i = 0; i < this.cacheColumns.length; i++){
  45.  
  46.                                     row.append(this.cacheColumns[i]);                              
  47.  
  48.                             }
  49.  
  50.                             this.cacheColumns = [];
  51.  
  52.                             collectionView.$(".jsListImages").append(row);
  53.  
  54.                     }
  55.    
  56. Collection -> Item
  57.    
  58. Collection -> Collection -> Item
  59.    
  60. View.ImageMultiUploader = Marionette.CompositeView.extend({
  61.     template : '#common-multi-imageuploader-composite',
  62.  
  63.     itemView : ImageMultiItem,
  64.  
  65.     colAmount : 3, // How many columns we got.
  66.  
  67.     cacheColumns : [], // appendHtml uses this. don't change.
  68.  
  69.     /**
  70.  
  71.      * Custom implementation of appendHtml, using this, we can use row/column
  72.  
  73.      * principle on a collection.
  74.  
  75.      */
  76.  
  77.     appendHtml : function(collectionView, itemView, index) {
  78.  
  79.         this.cacheColumns.push(itemView.el);
  80.  
  81.         // If current index (+1) has rest of 0 when we devide it by column amount
  82.  
  83.         // OR
  84.  
  85.         // End of array loop.
  86.  
  87.         if (((index + 1) % this.colAmount) === 0
  88.                 || index == this.collection.length - 1) {
  89.  
  90.             var row = $('<div class="row-fluid" />');
  91.  
  92.             for ( var i = 0; i < this.cacheColumns.length; i++) {
  93.  
  94.                 row.append(this.cacheColumns[i]);
  95.  
  96.             }
  97.  
  98.             this.cacheColumns = [];
  99.  
  100.             collectionView.$(".jsListImages").append(row);
  101.  
  102.         }
  103.  
  104.     },
  105.  
  106.     onRender : function() {
  107.  
  108.         console.log(this.collection)
  109.  
  110.     }
  111.  
  112. });
  113.    
  114. [
  115.     [{id: 1, title="test 1"},        {id: 2, title="test 2"},        {id: 3, title="test 3"}],
  116.     [{id: 4, title="test 4"},        {id: 5, title="test 5"},        {id: 6, title="test 6"}]
  117. ]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top