javascript - 使用 ng-options 在选择下拉列表中显示对象数据

标签 javascript html angularjs

我正在尝试将 angularJS 与 Symfony2 一起使用。 对于初学者,我尝试使用 ng-options 将对象的文本属性显示为简单下拉列表中的选项。 这是 HTML

    <div ng-app="demoAddList" ng-controller="myCtrl">
    <select ng-model="selectedProgram"  ng-options="programofinterest.id as programofinterest.text for programofinterest in programofinterests">
            </select>
        </div>
<p>Try to add the same item twice, and you will get an error message.</p>

这是脚本

var app = angular.module("programDropdown", []);
app.controller("myCtrl", function($scope) {
        $scope.programofinterests = [
            {id: '0', text: 'Masters - Information Systems Management'},
            {id: '1', text: 'Masters - Software Engineering'},
            {id: '2', text: 'Masters - Computer Security'},
            {id: '3', text: 'Bachelors of Computer Science'},
            {id: '4', text: 'Exchange Program'},
            {id: '5', text: 'Study Abroad'},
            {id: '6', text: 'Scientific Summer School'},
            {id: '7', text: 'French Summer School'},
            {id: '8', text: 'ME - Global IT Management'},
            {id: '9', text: 'ME -  Software Development and Multimedia'},
            {id: '10', text: 'ME - Systems, Networks and Security'}
        ];
});

但是结果是空的下拉列表。看一下屏幕截图的左上角 enter image description here

有什么想法吗?

最佳答案

首先尝试修复“JQuery”和“require”问题。这可能也会解决您的 Angular 问题,但不能保证,因为 Angular 通常不需要 JQuery。它嵌入了一种轻量级的 JQuery。

您可以在 Controller 中放置一个断点,然后查看调试器是否到达那里。

关于javascript - 使用 ng-options 在选择下拉列表中显示对象数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38047064/

相关文章:

javascript - Angularjs:将鼠标悬停/离开事件分配给 li 标签的子元素

angularjs - "angular.js line 12502 > function"多次自动添加

javascript - 为scrollTop添加延迟?

javascript - javascript 中 if false 语句总是返回 undefined 吗?

javascript - VueJS - 从本地 json 文件读取数据到 vis.js 时间线

html - 将父 div 拉伸(stretch)到表格内容的宽度

javascript - 单击时更改背景颜色

javascript - lodash/下划线;比较两个对象并删除重复项

javascript - Google 图表 LineGraph 切换数据表和维护状态

python - 使用 Django/HTML/Python 不显示表单