jQuery Masonry remove function example

半腔热情 提交于 2019-12-07 16:39:40

问题


I have implemented jQuery masonry to our site and it works great. Our site is dynamic and users must be able to add/remove masonry box's. The site has an add example but no remove example. Our db is queried returning x number of items. Looping through they are loaded and displayed. Here's a code sample: (we are use F3 framework and the F3:repeat is it's looping mechanism.).

<div id="container" class="transitions-enabled clearfix" style="clear:both;">
   <F3:repeat group="{{@productItems}}" value="{{@item}}">
      <div id="{{@item.itemId}}">
         <div class="box">
            <div class="view"> <!-- for css -->
               <a onclick='quickRemove("{{@item.itemId}}")>
                  <img src="{{@item.pic}}" />
               </a>
            </div>
            <p>
            {{@item.title}}
            </p>
         </div> 
      </div>
   </F3:repeat>
</div>

In the javascript code the item id number is unique and is passed into the function. It's also the div id# to distinguish each box. I've tried various combinations and methods but can't seem to get this to work.

function quickRemove(item){
    var obj = $('#'+item+'').html(); // item is the product id# but also the div id#
    $('#container').masonry('remove',obj);

    $('#container').masonry('reloadItems');
    $('#container').masonry('reload');
}

Has anyone out there successfully removed an item and how did you do it? Thx.


回答1:


Currently you appear to be passing a string full of html to the masonry remove method. Pass it the actual jQuery wrapped element by not including .html()

function quickRemove(item){
    var obj = $('#'+item+''); // item is the product id# but also the div id#
    $('#container').masonry('remove',obj);

    $('#container').masonry('reloadItems');
    $('#container').masonry('reload');
}


来源:https://stackoverflow.com/questions/12983204/jquery-masonry-remove-function-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!