我从一个方法返回了一个结果(它收集了多个对象),我正在尝试显示每个对象的属性(特别是那些)...但它只显示最后一个通知列表中的对象。
以下是我的剧本:
<script>
$(document).ready(function() {
$('.dropdown-toggle').on('click', function() {
// Add loading state
$('.menu').html('Loading notifications ...');
// Set request
var id = "{{ Auth::user()->id }}";
var request = $.get('/notifications/' + id);
// When it's done
request.done(function(response) {
console.log(response);
for(var index in response) {
if (response.hasOwnProperty(index)) {
var attr = response[index];
$('.notification-list').html(attr.action + ' By: ' + attr.added_by + ' : ' + attr.created_at)
}
}
});
});
});
</script>
答案 0 :(得分:1)
我认为你每次都会投入新的价值观。试试这个:
<script>
$(document).ready(function() {
$('.dropdown-toggle').on('click', function() {
// Add loading state
$('.menu').html('Loading notifications ...');
// Set request
var id = "{{ Auth::user()->id }}";
var request = $.get('/notifications/' + id);
// When it's done
request.done(function(response) {
console.log(response);
for(var index in response) {
if (response.hasOwnProperty(index)) {
var attr = response[index];
$('.notification-list').append(attr.action + ' By: ' + attr.added_by + ' : ' + attr.created_at)
}
}
});
});
});
</script>