我的 json 对象的每个值都被添加到“listOfCountries”两次。我不明白为什么它会循环两次结果对象。任何帮助,将不胜感激!
var listOfCountries = []
$(document).ready(function () {
$.ajax({
url: '/Json/GetCountries',
type: 'GET',
success: function (result) {
$.each(result, function (name, value) {
listOfCountries.push(value.Country);
});
$("#countriesAutoComplete").kendoAutoComplete(listOfCountries);
}
});
});
通过网络发送的 Json 对象:
[{"Country": "United States Of America"},{"Country": "Australia"},{"Country": "Britain"}]
html
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
<p>
Country: <input id="countriesAutoComplete" class="k-input" />
</p>
</div>
<script type="text/javascript" src="~/Scripts/Custom.js"></script>
</body>
</html>