gpt4 book ai didi

javascript - 使用 js 选择选择框(通过 angularjs 填充选择框)

转载 作者:行者123 更新时间:2023-11-30 16:46:17 24 4
gpt4 key购买 nike

我很难选择在 angularJS 的帮助下生成的选择框,任何人都可以告诉我我做错了什么或建议一些代码来纠正它-

        <meta charset="utf-8">
<title>Bughound: Update Bug</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.4/angular-filter.js"></script>
<script src="javascripts/jquery-1.10.12.js"></script>
</head>
<div class="margin custom">
<body bgcolor="#2e2e2e">
<form method="POST" action="update_bug_db.php">
<script type="text/javascript">
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}
$(document).ready(function () {
var progname = getURLParameter('prog_name');
var prognumber = getURLParameter('prog_number');
var progrelease = getURLParameter('prog_release');
//myvar = getURLParameter('myvar');
// String progname = request.getParameter("prog_name");
// String prognumber = request.getParameter("prog_number");
// String progrelease = request.getParameter("prog_release");
//$("#program_name").val(progname);
$("#program_number").val(prognumber);
$("#program_release").val(progrelease);
//$("#report_type").val('Documentation');
$("#program_name option[value=progname]").prop('selected', true);
$("#report_type option[value='Documentation']").prop('selected', true);
});
</script>
<div style="text-align: center; padding-top: 0px">
<h1 style="color:white;font-size: 50px">Bughound</h1>
</div>
<?php
require "db/db.php";
$bugid = $_GET['bugid'];
$sql = 'Select * from Bug where Bug_ID="' . $bugid . '"';
$result = db($sql);
$bug = $result->fetch_assoc();
?>

<div class="effect8">
<div class="tableMargin">
<table class="table" ng-app="myApp" ng-controller="customersCtrl">
<tr class="program_row">
<td class="td">Program</td>
<td class="td" style="padding-left: 2.7em">
<select class="dropdown" id="program_name" required ng-model="selectProgram" name="program">
<option></option>
<option ng-repeat="x in programes | unique: 'progname'" value=""{{x.progname}}"">{{ x.progname }}</option>
</select>
</td>
<td class="td" style="padding-left: 1em">Version</td>
<td class="td" style="padding-left: 0.8em">
<select class="dropdown" id="program_number" required ng-model="selectNumber" name="version">
<option></option>
<option
ng-repeat="x in programes | filterBy: ['progname']:selectProgram | filterBy: ['progrelease']:selectRelease | unique: 'prognumber'"
name="" {{x.prognumber}}"" value="" {{x.prognumber}}"">{{ x.prognumber }}</option>
</select>
</td>
<td class="td" style="padding-left: 1em">Release</td>
<td class="td">
<select class="dropdown" id="program_release" required ng-model="selectRelease" name="release">
<option></option>
<option
ng-repeat="x in programes | filterBy: ['progname']:selectProgram | filterBy: ['prognumber']:selectNumber | unique: 'progrelease'"
name="" {{x.progrelease}}
"">{{ x.progrelease }}</option>
</select>
</td>
</tr>
</table>

<script>
var app = angular.module('myApp', ['angular.filter']);
app.controller('customersCtrl', function ($scope, $http) {
$http.get("db/program_db.php")
.success(function (response) {
$scope.programes = response.records;
});
});
</script>

</table>

如您所见,脚本标记中间有很多注释代码,它响应更改函数,这里我通过 GET 获取 jsp 中的值。我能够正确地获得这些值。问题是使选择框被选中为某些值,我已经尝试了一些代码,您可以在同一脚本标签中看到这些代码。

最佳答案

我在选项上使用 ngRepeat 从来没有取得过太大的成功。 Angular 内置了对生成 select 元素的 options 的支持。查看他们的 ngOptions 文档。

ngOptions Documentation

您的情况的示例是:

<select class="dropdown" id="program_name" required ng-model="selectProgram" name="program" ng-options="x.progname for x in programes track by x">
<option value=""></option> <----//Default option
</select>

然后在您的 Controller 中您应该可以访问

selectProgram.progname

获取选中的名字

编辑

过滤您的选项,您可以像这样在ng-options中添加它:

<select class="dropdown" id="program_name" required ng-model="selectProgram" name="program" ng-options="x.progname for x in programes track by x | unique:'progname'">
<option value=""></option> <----//Default option
</select>

看看这个 answer

关于javascript - 使用 js 选择选择框(通过 angularjs 填充选择框),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31186917/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com