http://ivaynberg.github.io/select2/'dan select2 jquery eklentisini kullanıyorum.initSelection, select2 jquery eklentisinde çağrılmadı
Aşağıdaki kodu kullanıyorum.
$(document).ready(function() {
$("#e6").select2({
placeholder: "Search for a movie",
minimumInputLength: 1,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json",
dataType: 'jsonp',
quietMillis: 1000,
data: function (term, page) {
return {
q: term, // search term
page_limit: 10,
apikey: "ju6z9mjyajq2djue3gbvv26t" // please do not use so this example keeps working
};
},
results: 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 remote JSON data
return { results: data.movies };
}
},
initSelection: function (element, callback) {
var id = 9942;//$(element).val();
alert('initSelection');
if (id !== "") {
$.ajax("http://api.rottentomatoes.com/api/public/v1.0/movies/" + id + ".json", {
data: {
apikey: "ju6z9mjyajq2djue3gbvv26t"
},
dataType: "jsonp"
}).done(function (data) { callback(data); });
}
},
formatResult: movieFormatResult, // omitted for brevity, see the source of this page
formatSelection: movieFormatSelection, // omitted for brevity, see the source of this page
dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
});
});
$(document).ready(function() {
$("#e6").on("select2-selecting", function (e) {
var v = 10;
alert("selecting val=" + e.val + " choice=" + JSON.stringify(e.choice));
var id = document.getElementById('<%= savebtn.ClientID %>');
id.value = e.val;
id.click();
});
});
Sorun: Bazı nedenlerden dolayı initSelection denilen almıyor ve bu nedenle, post-sırt boyunca metin için değer ayarlamak mümkün değilim.
http://ivaynberg.github.io/select2/ sitesinden yükleme uzak veri örneğini kullanıyorum.
Ben initSelection için documentation bakıp diyor " Bu işlev yalnızca ilk giriş işlenecek olduğunda çağrılır.", Anlamını tam olarak ne emin değilim.Yanlış bir şey yapıyorum? Lütfen yardım
Teşekkürler!!! Bu – SharpCoder
çalışır Bu doğru. Bir initSelection işlevi sağlasanız bile, select2, "value" değerini sağlamazsanız, onu çağırmamaya karar verir. Yani, bir değer attrini kullanmak zorundasın, ya da birini sağla ve kullanmayacaksın. – fastmultiplication
Sorun şu ki bu seçili çoklu seçenekler için işe yaramaz –