【发布时间】:2015-05-12 02:57:14
【问题描述】:
我正在尝试从对象的属性中打印出每个数组项:
{
position:"Finance Office Assistant",
employer:"Washtenaw County Finance Department",
location:"Ann Arbor, MI",
start_date:"2012",
current: false,
end_date:"2012",
duties: [
"Item 1",
"Item 2",
"Item 3"
]
},
此对象与其他几个对象位于一个数组中。我正在尝试创建一个函数,该函数循环遍历所有对象并在无序列表中打印出 duties 数组项,其中包含列表项和数组项的确切数量。
这是我为完成任务而尝试编写的函数
$scope.dutyList = function() {
var arrayLength = $scope.duties.length;
while (arrayLength > 0) {
console.log("dutyList run")
document.write("<li> {{ dutyList }} </li>");
--arrayLength;
}
}
【问题讨论】:
-
你从你的代码中看到了什么结果,它与你想要的有什么不同?
标签: javascript arrays angularjs loops while-loop