Last active
December 19, 2015 00:29
-
-
Save venblee/5868758 to your computer and use it in GitHub Desktop.
Using Select Viewmodel to preload and AJAX for calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#PostalCitySelect').select2({ | |
initSelection: function(element, callback) { | |
var data = { id: $("#Supplier.PostalCityId").attr("value"), text: $("#Supplier_PostalCity_City").attr("value") }; | |
callback(data); | |
@* $.ajax('@Url.Action("SearchCityById", "Suppliers")', { | |
data: { | |
searchTerm: $("#Supplier_PostalCity_CityId").attr("value") | |
}, | |
dataType: "json" | |
}).done(function (data) { alert(data), callback(data); }); | |
*@ | |
}, | |
placeholder: 'Select an City', | |
minimumInputLength: 4, | |
ajax: { | |
url: '@Url.Action("SearchCity", "Suppliers")', | |
dataType: 'json', | |
data: function(term, page) { | |
return { | |
searchTerm: term | |
}; | |
}, | |
results: function(data, page) { | |
return { results: data }; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment