<table class="form-table" id="recHouseTable">
    <tbody>
        <tr>
            <th style="width:11.7%"><label for="traffic" style="margin-left: 30px">推荐房源:</label></th>
            <td>
                <div id="houseImg">
                </div>
                <button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt">
                    添加房源
                </button>
            </td>
        </tr>
    </tbody>
</table>
<script>
    (function($){
        {% if recommends %}
            var data = {{ recommends|json_encode()}};
        $.each(data,function(i,item){
            item.path = "{{siteUrl}}"+item.path;
            addRecHouse(item);
        });
        {% endif %}
        $(document).ready(function(){

            var urlParams = getUrlParmas();
            init_modal_houseList(addRecHouse,urlParams.page);

            //删除推荐房源
            $("#houseImg").on("click",".imgCancel",function(){
                $(this).parents("p").remove();
            });
        });

        function addRecHouse(data){
            var recommendHouse = $("<input>").attr({"type":"hidden","name":"data[recommend][]","value":data.id});
            var url = url;
            var img = $("<img>").attr({"src":data.path,"height":90,"width":140,"style":"margin-right:50px;margin-bottom:10px;"});
            var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action imgCancel");
            var p = $("<p>").append(img).append(cancel).append(recommendHouse);
            $("#houseImg").append(p);
            controlCommand("houseImg",3,0);
        }
    })(jQuery);

</script>