<br />
<div class="row">
    <div class="col-md-12">
        <label for="housename">标题：</label>
        <input name="housename" id="housename" type="text" value="{{result.name}}" class="form-control" >
    </div>
</div>
<br />
<table class="form-table">
    <tbody>
    <tr>
        <th><label for="mark">标签</label></th>
        <td>
            <div id="mark" class="row">
            </div><br/>
            <button type="button" class="button action" id="addTagBtn">
                标签
            </button>
        </td>
    </tr>
    </tbody>
</table>

<script>
    $(document).ready(function () {
        {% set markOld = function('SearchDao::searchFeatureOld', houseId, 0)|json_encode() %}
        {% if markOld %}
            var data = {{ markOld }};
        $.each(data, function (i, item) {
            addTag(item.tag_id, item.name);
        });
        {% endif %}

        var tagArray = [];
        $('#addTagBtn').click(function(){
            init_modal_addTag(0, function (id, value) {
                tagArray = [];
                $('input[name="data[houseTag][]"]').each(function (index, item) {
                    tagArray.push(Number($(item).val()));
                });
                if(tagArray.indexOf(Number(id)) == -1){
                    addTag(id, value);
                }else{
                    alert('不能重复选择标签');
                }
            });
        });
    });
    function addTag(id, value) {
        var houseTag = $("<input>").attr({"type": "hidden", "name": "data[houseTag][]", "value": id});
        var cancel = $("<span>").attr("aria-hidden", "true").addClass("glyphicon glyphicon-remove featureCancel ");
        var span = $("<span>").attr("style", "margin-right:5px").append(value);
        var divCol = $("<div>").append(houseTag).append(span).append(cancel).addClass("col-md-3").attr("style", "margin-bottom:10px");
        $("#mark").append(divCol);
    }
</script>