如何将json数据显示为optgroup,并在angularjs中的Select Option中进行多选

时间:2017-02-23 09:33:03

标签: javascript angularjs json ionic-framework

我尝试将jSON数据显示为optgroup选项,并在angularjs中进行多选,但未获得成功

在Html中显示为:

<select ng-model="industrycatslect" ng-change="industryslected(industrycatslect)" multiple   ng-options="skilldata.value as skilldata.value group by skilldata.group for skilldata in skillCategory track by skilldata.id">
    <option value="">Select Location</option>
</select>

JSON显示为:

"skillCategory": [
        {
            "id": "8",
            "group": "Technology",
            "value": " Software Engineering"
        },
        {
            "id": "17",
            "group": "Technology",
            "value": "Collaboration and Content Management"
        },
        {
            "id": "22",
            "group": "Functions",
            "value": "Procurement"
        },
        {
            "id": "23",
            "group": "Functions",
            "value": "Product"
        }
    ],

请帮助我,我认为我在“ng-options”中犯了一些错误。

1 个答案:

答案 0 :(得分:1)

我认为这可能会帮助你。您如何定义skillCategory JSON数据时出错。我希望这个JSFiddle有所帮助。它没有按ID排序,但它按预期显示元素:

Answer 1