【发布时间】:2017-05-18 03:34:06
【问题描述】:
我正在使用 ng-repeat 在前端使用 AngularJS 填充来自 REST API 的响应。我正在为用户提供修改屏幕上显示的每个结果的选项。当用户修改特定员工的值时(假设他正在更改下拉菜单),当单击该员工的修改记录链接时,其他员工的 HTML 也会反映出这一点。我应该怎么做才能使搜索响应中的详细信息显示在 HTML 中。这是我的搜索回复
var searchresponse = [{
"items": [{
"employeeId": "ABC",
"type": "D",
"alive": "Yes"
}, {
"employeeId": "DEF",
"type": "D",
"alive": "Yes"
}, {
"employeeId": "NPK",
"type": "D",
"alive": "Yes"
}, {
"employeeId": "PKN",
"type": "D",
"alive": "Yes"
}],
"more": false
}];
我将结果设置为搜索响应的控制器代码
$http.post('http://localhost:8080/services/employee/search/'+Systems+"", searchCriteria)
.then(function(response) {
$scope.searchresponse= [];
$scope.searchresponse = response.data.items;
}
这就是我将结果页面上的值显示为列表的方式。
<tr ng-repeat="details in searchresponse">
<td class=list align=center ng-switch="details.type">
<span
ng-switch-when="D">SINGLE</span><span
ng-switch-when="E">MULTIPLE</span>
</td>
假设我将员工 ABC 的值从 D 更改为 E。当我单击员工 PKN 的修改链接时,它正在加载选择为 E 的下拉列表。为什么我为特定员工所做的更改会反映给其他员工。
这是我用来加载 HTML 值的函数。在 HTML 中,我已将它们声明为 ng-model
$scope.ModifyEmployeeConfig = function(details ){
$scope.type= "" ;
$scope.type= details.type; // I tried printing the value and see here the value in response only getting printed
}
这是我的 HTML
<select name="type" class="pulldown1" id="type" ng-model="type">
<option value="D">Single</option><option value="E">Multiple</option>
</select>
【问题讨论】:
-
将
<tr ng-repeat="details in searchresponse">更改为<tr ng-repeat="items in searchresponse">,前提是您在控制器中使用$scope.searchresponse = searchresponse -
我试过了,没用。我正在分配这样的响应 $scope.searchresponse = response.data.items;
-
您可以粘贴您的控制器代码,以便我们指出问题所在。我建议在某处打印 response.data。
-
已更新问题
-
我想做的是 .我在单个页面上使用 ng-repeat 显示我的结果,并带有要修改的超链接。当用户单击修改新页面时,会显示结果页面上显示的数据。当我在此处将值从 D 更改为 E 时(修改页面)。当我点击他们的修改链接时,它也会反映到其他记录中。范围变量是相同的。只有 HTML 被改变了
标签: javascript html angularjs angularjs-scope