gpt4 book ai didi

javascript - Angular : How do I get a column in a table with a dropdown in each cell and set different values in each of these dropdowns?

转载 作者:行者123 更新时间:2023-11-28 06:21:34 24 4
gpt4 key购买 nike

我对 Angular 很陌生,我正在尝试为用户信息创建一个表。

<div ng-controller="ContactController as cc" ng-app="MyApp" id="account-settings-page">
<div class="slds manage-account-table">
<table class="slds-table slds-table--bordered slds-table--striped">
<thead>
<tr class="slds-text-heading--label" role="header">
<th data-label="staffName" class="slds-is-sortable">Selected Portal User</th>
<th data-label="title">Title</th>
<th data-label="email">Email</th>
<th data-label="phone">Portal Admin</th>
</tr>
</thead>
<tbody ng-model="users">
<tr ng-repeat="user in users" class="slds-hint-parent">
<td data-label="contactName">
<select class="slds-select" ng-model="users">
<option value="{{user.contactName}}" ng-repeat="user in users">{{user.contactName}}</option>
</select>
</td>
<td data-label="contactTitle">{{user.contactTitle}}</td>
<td data-label="contactEmail">
<div>{{user.contactEmail}}</div>
</td>
<td data-label="isPortalAdmin">
<div class="impact-thesis-checkbox">
<div class="slds-form--stacked">
<div class="radio">
<label><input type="radio" name="optradio" ng-checked="{{user.isPortalAdmin}}"></label>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>

JavaScript:

angular
.module('MyApp',[])
.controller('ContactController', function($scope) {
var self = this;
self.data = {
"users": [{
"userId": "001290000031Xp0",
"userName": "Joe Salademaier",
"contactId": "001290000031Xp0",
"contactName": "Joe Salademaier",
"contactTitle": "CEO",
"contactEmail": "joe@organization.org",
"isPortalAdmin": true,
"isUser": true
}, {
"userId": "001290000031Xp0",
"userName": "Anastasia Smith",
"contactId": "001290000031Xp0",
"contactName": "Anastasia Smith",
"contactTitle": "CTO",
"contactEmail": "asmith@organization.org",
"isPortalAdmin": false,
"isUser": true
}, {
"userId": "001290000031Xp0",
"userName": "Bill Salademaier",
"contactId": "001290000031Xp0",
"contactName": "Bill Salademaier",
"contactTitle": "CMO",
"contactEmail": "bill@organization.org",
"isPortalAdmin": false,
"isUser": true
}, {
"userId": "001290000031Xp0",
"userName": "Joe Schmope",
"contactId": "001290000031Xp0",
"contactName": "Joe Schmope",
"contactTitle": "VP Finance",
"contactEmail": "bill@organization.org",
"isPortalAdmin": false,
"isUser": true
}, {
"userId": "001290000031Xp0",
"userName": "Jill Meiser",
"contactId": "001290000031Xp0",
"contactName": "Joe Salademaier",
"contactTitle": "VP Marketing",
"contactEmail": "bill@organization.org",
"isPortalAdmin": false,
"isUser": true
}, {
"userId": "",
"userName": "",
"contactId": "001290000031Xp0",
"contactName": "Rajesh Gupta",
"contactTitle": "Developer",
"contactEmail": "raj@always.org",
"isPortalAdmin": false,
"isUser": false
}, {
"userId": "",
"userName": "",
"contactId": "001290000031Xp0",
"contactName": "Jill Sedelmaier",
"contactTitle": "Senior Consultant",
"contactEmail": "jill@never.org",
"isPortalAdmin": false,
"isUser": false
}]
};
$scope.users = self.data.users;
});

我需要在表中获取联系人姓名、联系人职务、联系人电子邮件列和表示 bool 值的字段的数据。虽然我已成功获取最后三列的值,但我无法在第一列中设置该值,该列应该是下拉列表。我有两个问题:1. 如何为每个用户设置下拉列表中的值?2. 当我更改所选用户时,如何使行值发生变化?

这是我在 Codepen 上尝试的链接:http://codepen.io/Gromit/pen/qbwmvZ

最佳答案

这可能会帮助您下拉:AngularJS: Get selected Text and Value of HTML Select DropDownList using ng-change请记住,Angular 的一大优点是它能够动态将数据链接到您的 View ,因此您可以向数据添加“显示”标志(true 或 false)并使用 ng-if ="data.show"或 ng-show="data.show"使用更改 data.show 值的函数过滤结果,具体取决于下拉列表的值...只是一个想法,它取决于你是如何设计的...抱歉,如果我误导了你,但我不清楚它是否正是你想要的...

从示例中:

<tr>
<td>
<select ng-model="selectedItemVarUser" ng-options="d.userId as d.userName for d in data track by d.Id"
ng-change="GetValue()">
</select>
</td>
...
</tr>

关于javascript - Angular : How do I get a column in a table with a dropdown in each cell and set different values in each of these dropdowns?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35484069/

24 4 0