java スクリプトに関数があり、それを使用して asp.net mvc コントローラーから JSON を取得し、ビューにアイテムを表示します。
<script type="text/javascript" language="javascript">
var k = 0;
var record_count = 0;
var col_count = 3;
var row_count = record_count / col_count;
var str = "<table>";
function itemTemplate() {
var url = '<%: Url.Content("~/") %>' + "ProductListing/AllProductListing/0";
$.getJSON(url, function (product) {
$.each(product.ja, function (index, value) {
//append rows and column to my table by concat the string of 'str'
});
});
str += '</table>';
alert(str);
return (str);
}
$(document).ready(function () {
alert(itemTemplate());
});
</script>
問題 : 関数内の$(document).ready
関数をアラートすると、最初はアラート<table></table>
であり、関数内で連結した完全な文字列をアラートし続け$.getJSON
ます。したがって、関数は JSON を取得する前に返されます。
誰でもそれについて何か考えがありますか?ありがとう。