我从离子应用程序中的数据库中获取以下数据。我将它保存到$ scope.dbCustomersArray:
[
{
"customer_id":1,
"customer_name":"Test Company",
"customer_address":"17 Morena Blvd Camarillo",
"customer_city":"Ventura",
"customer_contactnumber":"805-832-6163",
"Company_id":1
},
{
"customer_id":2,
"customer_name":"Another test company",
"customer_address":"2742 Distribution Way Metairie",
"customer_city":"Jefferson",
"customer_contactnumber":"504-979-9175",
"Company_id":1
},
{
"customer_id":3,
"customer_name":"Final test company",
"customer_address":"775 W 17th St San Antonio",
"customer_city":"Bexar",
"customer_contactnumber":"210-812-9597",
"Company_id":1
}
]
我试图在我的HTML中循环播放它。
<label class="item item-input" style="padding: 0px">
<div class="row">
<label class="item item-input item-select col">
<div class="input-label" style="visibility: hidden">
Customer
</div>
<select>
<option> -- Customer -- </option>
<ion-item ng-repeat="customer in $scope.dbCustomersArray">
<option> Hello, {{customer.customer_name}}! </option>
</ion-item>
</select>
</label>
</div>
</label>
我没有返回值,也没有在日志中出现任何错误。我尝试使用以下代码遍历$ scope.dbCustomersArray,但打印出的唯一值是:0
,1
和2
。
for (var customer in $scope.dbCustomersArray) {
console.log("LOGGING A CUSTOMER - " + customer.customer_name);
}
请帮我解决这个问题。我不明白我哪里出错了。提前谢谢。
修改
当我点击客户选择列表时,我无法在我的离子应用程序中看到数组中的值。
答案 0 :(得分:0)
看起来你有两个问题:
当你遍历对象数组时,0,1,2听起来很准确,因为那些是你的数组索引。我认为确认您的控制器已加载并删除$ scope将纠正您的问题。
此致