<table class="form-table">
    <tbody>
        <tr>
            <th><label for="traffic">推荐房源</label></th>
            <td>
                <div id="houseImg">
                </div><br />
                <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"});
            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>