我可以在ng-options中访问Object的索引吗?

时间:2015-07-16 09:55:43

标签: angularjs ng-options

我在对象数组中使用ng-options显示数据。

的index.html

app.controller('Ctrl', function ($scope) {

$scope.array_object = [
    {"id": "a", "label": "A", "my_array": [1, 2, 3, 4]},
    {"id": "b", "label": "B", "my_array": [1, 4, 8]},
    {"id": "c", "label": "C", "my_array": [2,6]}
];

$scope.get_my_array = (function() {
      console.log($scope.object_choose); //It work and show "id" a , b , c
      console.log($scope.object_choose.my_array); //It not work
  });  

});

controller.js

{{1}}

我可以在Object中获取数组。

1 个答案:

答案 0 :(得分:2)

最简单的方法是使用以下内容存储模型中的实际值:

console.log($scope.object_choose.id);       // a , b , c
console.log($scope.object_choose.my_array); // the array

然后您可以按如下方式访问它:

$sql="SELECT `Variant`, COUNT(`Variant`) AS tsold,
      MONTHNAME(sold_date) AS mname
      FROM `vehicle_sold`
      GROUP BY MONTH(`sold_date`), `Variant` ";
while($row = mysqli_fetch_array($result)) {
    echo $row["Variant"],"---",$row["mname"],"---",$row["tsold"],"<br/>";     
}

诀窍是要了解可以编写表达式的许多方法来操纵数据的存储和显示方式。 https://www.agiliq.com/blog/2019/04/drf-polls/包含您需要的所有信息。