【发布时间】:2017-01-15 13:35:07
【问题描述】:
我的 Angular 应用中有两个下拉菜单。当我在第一个下拉菜单中选择一个选项时,我希望该选择影响第二个下拉菜单。示例:第一个菜单将包含状态消息列表。当我选择“需要维护”时,它会将第二个菜单更改为与维护相关的部门。或者如果我选择“丢失”状态,它会将第二个菜单更改为与丢失状态相关的部门。这是我的代码和设置:
.controller('HomeCtrl', function($scope, $rootScope, $http, $ionicPlatform) {
// This disables the user from being able to go back to the previous view
$ionicPlatform.registerBackButtonAction(function (event) {
event.preventDefault();
}, 100);
// This function only gets called when the submit button is hit on the messaging screen. It posts to server for sending of message
$scope.submit = function() {
$http.post('http://localhost:8000/', {
messageText: $scope.messageText,
name: window.localStorage.getItem("username")
});
$scope.messageText = ""; //clearing the message box
}
})
<div class="form1" ng-controller="HomeCtrl">
<form class="form">
<select placeholder="Select a Subject" ng-model="selectSubject" data-ng-options="option.subject for option in subject"></select>
<select placeholder="Select a Department" ng-model="selectDept" data-ng-options="option.dept for option in dept"></select>
<input type="text" class="messageText" placeholder="Message" ng-model="messageText">
<button class="button" ng-click="submit()"><span>Submit</span></button>
</form>
</div>
那是我的控制器与也发布的 html 相关。
我知道如何从存储信息的节点服务器获取我需要的信息。当在第一个菜单中单击一个选项时,我需要帮助弄清楚的是更改第二个菜单中的选项。
我想在单击一个选项时调用 http.get ,然后将填充第二个菜单。第一个菜单将是静态的,不会改变。
【问题讨论】:
-
分享您的 json 以获得更好的答案;检查此链接以获取示例advancesharp.com/blog/1189/…
-
什么意思?我现在没有json。每当我执行 http.get() 来填充下拉列表时,我的数据都来自节点服务器中的 mongodb 数据库。
-
所以你选择一个主题展示相关部门?也许您可以创建一个过滤器,当您从第一个菜单中选择某些内容时,该过滤器将应用于您的第二个菜单。
标签: javascript html angularjs node.js http