更新时间:2023-10-01 23:35:28
否. ECMAScript指定这样的哈希行为: http://bclary.com/2004/11/07 /#a-8.6
No. ECMAScript specifies hash behavior as such: http://bclary.com/2004/11/07/#a-8.6
对象是属性的无序集合.每个属性都包含一个名称,一个值和一组属性.
An Object is an unordered collection of properties. Each property consists of a name, a value and a set of attributes.
您不能假设给定像{"idfruits":"1","fruit":"Apple"}
这样的哈希,id将是第一个,水果将是第二个.您需要按名称称呼他们.
You cannot assume that given a hash like {"idfruits":"1","fruit":"Apple"}
, the id will be first and the fruit will be second. You will need to call them by name.
顺便问一下,很好的问题.
Very good question, by the way.
要做你想做的事:
<script type="text/javascript">
$(function () {
jQuery.ajax({
url: "index.php",
type: "POST",
dataype: "json",
async: false,
success: function (data) {
console.log(data);
var items = [];
$.each(data, function (key, fruit_info) {
items.push('<li id="fruit_' + fruit_info.idfruits + '">' + fruit_info.fruit + '</li>');
});
$(items.join('')).appendTo('#listy');
}
});
});
</script>