內部即時通訊使用選擇二引導https://select2.github.io/ 遠程數據提取通過AJAX,這裏面所有jQuery的中繼http://briandetering.net/repeater使用選擇二Jquery的中繼器不工作
<div data-repeater-item class="mt-repeater-item">
<!-- jQuery Repeater Container -->
<div class="mt-repeater-input">
<label class="control-label">First Team</label>
<br/>
<select name="equipe_1" id="select2-button-addons-single-input-group-sm" class="form-control js-data-example-ajax">
</select>
</div>
<div class="mt-repeater-input">
<label class="control-label">Second Team</label>
<br/>
<select name="equipe_2" id="select2-button-addons-single-input-group-sm" class="form-control js-data-example-ajax">
</select>
</div>
<div class="mt-repeater-input">
<a href="javascript:;" data-repeater-delete class="btn btn-danger mt-repeater-delete">
<i class="fa fa-close"></i> Delete</a>
</div>
</div>
這是我的HTML,但是當我點擊添加按鈕我有克隆的形式,但slect2 dropdonw不工作。
我Componement選擇二JS文件
$(".js-data-example-ajax").select2({
placeholder: "Choose a Team...",
width: "off",
allowClear: true,
multiple:false,
ajax: {
url: "http://test.dev/teamsearch",
dataType: 'json',
type: "POST",
delay: 2000,
data: function(params) {
return {
q: params.term, // search term
page: params.page,
_token: CSRF_TOKEN
};
},
processResults: function(data, page) {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return {
results: data
};
},
cache: true
},
escapeMarkup: function(markup) {
return markup;
}, // let our custom formatter work
minimumInputLength: 4,
maximumSelectionLength: 1,
templateResult: formatRepo,
templateSelection: formatRepoSelection
});
我jQuery的中繼文件:
var FormRepeater = function() {
return {
//main function to initiate the module
init: function() {
$('.mt-repeater').each(function(){
\t \t $(this).repeater({
\t \t \t show: function() {
$(this).slideDown();
\t \t },
\t \t hide: function (deleteElement) {
\t \t if(confirm('Are you sure you want to delete this element?')) {
\t \t $(this).slideUp(deleteElement);
\t \t }
\t \t },
\t \t ready: function (setIndexes) {
\t \t }
\t \t });
\t });
}
};
}();
jQuery(document).ready(function() {
FormRepeater.init();
});
進出口使用選擇二AJ斧頭加載隊列表裏面。
如何讓jquery中繼器複製我的表單時,select2工作? 謝謝
的深入概述我不明白這一點: $( 「P」)。鼠標懸停(函數() 它是一個事件監聽到HTML p標籤? 我需要調用初始化選擇2時,我按下按鈕克隆 – Tncoders
@Tncoders請參閱我的更新答案鼠標懸停在 –