我一直按照这个视频中的说明制作我自己的带有角度和选择的多选搜索下拉菜单。
我想知道是否有人可以帮助我弄清楚如何将选择保存到变量中,以便我可以将其从客户端发送到服务器端并将其用作 python 脚本的输入。最好,我想在点击时做到这一点。我添加了一个虚拟按钮...
我可以从 html 中访问 ng-model 值,但不能在应用程序/控制器中访问。
索引.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Choose</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="chosen.min.css">
<link rel="stylesheet" type="text/css" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<style type="text/css">
.span4 {
width: 300px;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="chosen.jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script type="text/javascript" src="js/the_app.js"></script>
</head>
<body>
<form action="#" class="container" ng-controller="JumpersController">
<h1>Choose:</h1>
<select data-placeholder="Choose" multiple class="span4 chzn-select" chosen ng-model="recipients" ng-options="recipient.name for recipient in jumpersList"></select>
<p ng-repeat="recipient in recipients">{{recipient.name}}</p>
<input type="button" ng-click="" value="Gimme!"></input>
</form>
</body>
</html>
the_app.js
var app = angular.module('myApp', []);
app.directive('chosen', function() {
var linker = function(scope,element,attr) {
scope.$watch('jumpersList',function() {
element.trigger("chosen:updated");
})
element.chosen();
};
return {
restrict:'A',
link: linker
}
})
app.controller('JumpersController', function($scope,$http) {
$scope.url = 'master_dict.json';
$scope.jumpersList = [];
$scope.fetchJumpers = function() {
$http.get($scope.url).then(function(result){
$scope.jumpersList = result.data;
});
}
$scope.fetchJumpers();
})