- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在创建一个应用程序,它将在选定的一天为老师列出类(class),每个类(class)都是屏幕上的一个按钮。此列表是使用 *ngFor
制作的,并从 ts 文件中提取数据,该文件最初来自 PHP/数据库查询。
然后老师会按下按钮以显示当天哪些学生应该上课。这是一款出勤/缺勤监控应用。
但是,我正在测试 *ngFor
来制作我的列表,因为数据存储为 3 个对象,每个对象都有一个学生的信息,所以 动态创建了三个按钮>*ngFor
- 事实上,由于三个学生在同一个类(class),我只需要一个按钮。
只需要为老师当天的下一节课创建下一个按钮。
我猜这是一个算法问题,或者可能需要进行不同的查询才能从 SQL 获取数据。我不知道。
我迷路了
HTML
<ion-list>
<ion-card padding *ngFor="let cour of planning; let i = index" (click)="showStudents($event, i)">
<h2>{{ cour.cours }}</h2>
<p>{{ cour.time }}</p>
<p>{{ cour.date }}</p>
<p>{{ cour.lieux }}</p>
<p>{{ cour.duration }}</p>
</ion-card>
</ion-list>
服务
getCoursList(date, idIntervenant) {
return this.http.post('http://localhost/Attendance App/myApp/src/app/api/getCours.php?id='+idIntervenant,
{ date, }).subscribe(data => {
console.log(Object.values(data));
let planningData = Object.values(data);
const grabArray = planningData[0];
const id = grabArray.intervenant;
if (id !== undefined) {
// console.log('test array', id);
let navExtras: NavigationExtras = {
state: {
planning: planningData
}
}
this.router.navigate(['/cours/', id], navExtras);
};
},
error => {
console.log(error);
});
}
PHP查询数据库
if (isset($_POST["date"])) {
// $id = $_POST["id"];
$origDate = date("Y-m-d", strtotime($_POST['date']));
$date = $origDate;
$id = $_GET['id'];
$stmt = $conn->prepare("SELECT * FROM planning WHERE intervenant = :id AND date = :date");
$stmt->execute([':id' => $id, ':date' => $date]);
if ($stmt->rowCount() > 0) {
$output = array();
$output = $stmt->fetchAll();
echo json_encode($output);
} else {
$errors = "No data found for this date";
echo json_encode($errors);
}
// $conn->close();
}
从 PHP 查询接收到的数据 - 1 个包含 3 个对象的数组
[object Array]: [Object, Object, Object]
0: Object
cours: "Suivi individuel"
date: "2019-07-06"
duration: "1h30"
etudiant: "james ross"
id_planning: 19
intervenant: "2"
lieux: "Nice 2"
time: "12:00"
__proto__: Object
1: Object
cours: "Suivi individuel"
date: "2019-07-06"
duration: "1h30"
etudiant: "Tupac Shakur"
id_planning: 20
intervenant: "2"
lieux: "Nice 2"
time: "12:00"
__proto__: Object
2: Object
cours: "Suivi individuel"
date: "2019-07-06"
duration: "1h30"
etudiant: "Joyner lucas"
id_planning: 21
intervenant: "2"
lieux: "Nice 2"
time: "12:00"
__proto__: Object
length: "3"
上面的三个学生都在同一时间去同一个类,所以我只想动态生成一个按钮。
如果那天老师有第二节课,它会生成第二个按钮,依此类推。
目前没有错误信息,我只是没有得到想要的结果。
最佳答案
看来您可能需要以不同方式构建数据库。与其在计划表中为每个学生排一行,不如考虑采用以下结构:
Table Student:
- studentId
- name
Table Teacher:
- teacherId
- name
Table Class:
- classId
- name
- description
- schedule (not sure what the format of this would be,
but using it your code should be able to determine the next meeting of the class)
Table Registration (each row in this table represents a student enrolled in the class):
- classId
- teacherId
- studentId
然后您的查询变为 SELECT * FROM Class WHERE teacherId=X
X 是已登录的教师。这将为您提供该教师所类的总列表。
要获取特定类(class)的学生列表,您可以执行以下操作:SELECT * FROM Registration WHERE classId=Y AND teacherId=X
Y 是从先前查询中检索到的类(class) ID 之一。
希望这能帮助您朝着正确的方向前进!
关于javascript - *ngFor 需要为每个不同的对象生成 1 个 btn,但将相似的对象值放在同一个 btn 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56907387/
如问题 vs. . Which to use? 中所写我使用: "" 关于javascript - 带下划线的文本问题,我们在Stack Overflow上找到一个类似的问题: https://s
如何在“btn btn-block btn-lg btn-primary”按钮上添加“下拉切换”? 我有这样的链接“btn btn-block btn-lg btn-primary” Download
在 bootstrap 中,很多天以来一直困扰我的一件事是,当在 HTML 中包含 bootstrap 类时,我不理解标记背后的概念。 喜欢- press me 为什么有两个? btn 和 btn
我正在制作一个类似这张图片的广播组: 但我想删除最后两个 btn-groups 之间的垂直空间。 我怎样才能做到这一点? 我的 html: 2011 2012
我想要导航栏中的 btn(它只出现切换)获得 btn-info 颜色。 我添加了一个 btn-info 类, btn的文字颜色变为白色 btn 颜色没有改变。 我使用默认的 bootstrap 3 c
如何并排水平对齐我的 3 个按钮?我认为它现在看起来很糟糕。 class= btn btn-danger 我该如何编写它的 css? 我的代码 Statio
在 twitter-bootstrap 2 中,有一个 btn btn-mini我在 Bootstrap 3 中找不到对应的类。 Bootstrap 3 中的等价物是什么? 最佳答案 如果您阅读 do
我希望 btn-primary 颜色按钮以 btn-success 的颜色淡入淡出,其中 data-id = 单击的 ID。 我不知道如何使用单击的 ID 制作动画。尝试使用 $(".add_to_c
在我正在构建的应用程序中,我需要默认禁用一个按钮。 我需要 btn-danger默认情况下禁用,我需要它是 btn-xs所以它不会生成 tr占用太多空间。根据 bootstrap documentat
为什么这段代码不会崩溃? T 为零。如果T为nil,如何访问Caption? procedure Crash;
当我将 twitter bootstrap 3.0 危险按钮添加到我的代码并在 heroku 中运行它时,它看起来被遮住了。但是,当我在本地主机中运行该应用程序时,它看起来很正常。我使用的代码如下
我有一些带有 class="btn btn-small btn-success" 的 Twitter Bootstrap 按钮 按钮应该是绿色的,但现在是蓝色的。在 Chrome Web Inspec
我想实现一个 Bootstrap 按钮工具栏,如 getbootstrap.com 所示。具有附加行为:使用移动设备时,所有按钮组都应自动切换到垂直模式。 我认为最合适的解决方案如下: .myClas
我有两个按钮组,每个按钮在工具栏中包含两个按钮(总共 4 个按钮),并且希望每个按钮大小相同,并均匀分布在父 div 中(在本例中为 Bootstrap 列。是否有简单的方法来做到这一点? JSfid
我有以下按钮代码 示例 1 Logout 示例 2 Not Billable Entries 但是当我更改类时 btn btn-primar
我正在创建一个应用程序,它将在选定的一天为老师列出类(class),每个类(class)都是屏幕上的一个按钮。此列表是使用 *ngFor 制作的,并从 ts 文件中提取数据,该文件最初来自 PHP/数
这个问题在这里已经有了答案: Transparent text cut out of background (14 个答案) 关闭 5 年前。
我有一个 btn-toolbar,它有两个 btn-group。默认情况下,组向左对齐。但我需要第二个工具栏右对齐。 这是我的代码: Edit
在Bootstrap核心CSS或者类似的样式表中,.btn:active之后的.btn.active有什么作用? 最佳答案 :active of .btn:active 是一个 CSS 选择器,只要用
我有多个按钮共享同一个处理程序。单击 btn 时,我使用 addCls() 更改背景颜色。单击另一个 btn 时,我想从以前的 btn 中删除 Cls() 并将 addCls() 添加到新的 btn。
我是一名优秀的程序员,十分优秀!