【问题标题】:Show json array list in drop down angular以下拉角度显示 json 数组列表
【发布时间】:2018-05-15 07:22:56
【问题描述】:

我是 AngularJS 的新手,我试图在下拉列表中显示数据并且遇到一些错误。 这是我的 JSON 数据:

$scope.list=[
{
    "$id": "1",
    "Groups": [
        "xyz",
        "abc",
        "ugh",
        "ccd"
    ]
}
]

我正在尝试显示 json 中提到的组名称列表。

在控制器中:-

$scope.selectedval = $scope.list[0].Groups;
console.log($scope.selectedval);

查看我正在这样做:-

ng-options="item.Groups for item in list"

通过这样做,我可以在单个选项中获取所有数据。如何通过 ng-option 分隔每个列表上的数据?

【问题讨论】:

    标签: arrays angularjs json ng-options


    【解决方案1】:

    `ng-options="item for item in list[0].Groups"

    【讨论】:

    【解决方案2】:

    在视图中试试这个

    ng-options="val for val in selectedval"
    

    【讨论】:

    • 工作谢谢。显示在列表中,但选择它时,分解为字符。
    【解决方案3】:
    $scope.list:[{"$id": "1",
    "Groups": [
        "xyz",
        "abc",
        "ugh",
        "ccd"
    ]}]
    $scope.list=[] // replace ":" by "="
    

    【讨论】:

    • 好吧,对不起,我的错误实际上是 = only 。我正在编辑问题。还没来。
    猜你喜欢
    • 2019-05-24
    • 1970-01-01
    • 2018-10-25
    • 2022-06-13
    • 2022-11-13
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    相关资源
    最近更新 更多