我有两个数组Data1和Data2,我希望将这些数据中的数据(它们包含字符串)填充到两个不同部分的tableview中.第一部分应标题为"Some Data 1",第二部分标题为"KickAss".
我有两个部分填充第一个数组的数据(但没有标题).
到目前为止,这是我的代码:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var rowCount = 0
if section == 0 {
rowCount = Data1.count
}
if section == 1 {
rowCount = Data2.count
}
return rowCount
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
let ip = indexPath
cell.textLabel?.text = Data1[ip.row] as String
return cell
} …Run Code Online (Sandbox Code Playgroud) 我有一个带有 mat-table 和 mat-paginator 的 angular 项目,类似于以下内容:
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
<td mat-cell *matCellDef="let row"> {{row.id}} </td>
</ng-container>
<ng-container matColumnDef="progress">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Progress </th>
<td mat-cell *matCellDef="let row"> {{row.progress}}% </td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let row"> {{row.name}} </td>
</ng-container>
<ng-container matColumnDef="color">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Color </th>
<td mat-cell *matCellDef="let row" [style.color]="row.color"> {{row.color}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let …Run Code Online (Sandbox Code Playgroud) 在Angular7中,如何在选择项时显示其高度?我有以下组件文件:
import { Component, ViewEncapsulation } from "@angular/core";
import { FormControl } from "@angular/forms";
/** @title Select with multiple selection */
@Component({
selector: "select-multiple-example",
templateUrl: "select-multiple-example.html",
styleUrls: ["select-multiple-example.css"],
encapsulation: ViewEncapsulation.None
})
export class SelectMultipleExample {
toppings = new FormControl();
toppingList: string[] = [
"Extra cheese",
"Mushroom",
"Onion",
"Pepperoni",
"Sausage",
"Tomato",
"CBFnTQcZ79AeYrdq",
"1KiYwRjeqdqjNzVb",
"TeLvgGl7t3yHDrZE",
"s3ivzgLZO9qDNovJ",
"QOOH2MCNRRXVJNwD",
"1RWqdyPpu8yHSDoO",
"d3aAOYIWYJE695Lf",
"JoXDWP6zKSrZTIUc",
"hpxQKFJsJcgVey5A",
"UMI0akuHn2M5BaAP",
"LRnQgNNjpqZwpdzj",
"ZDIgw68mQyNLtxob",
"Q6HY6tcqFcySJqD9",
"WVFSg4TKeEqqoF1g",
"ka4ORT9rUW8EPaPd",
"ingfHsjBXAmt7yvo",
"G3MY6MowhI7s0fN9",
"ZlWqSoRnlhXQCbYz",
"gerR70hrO5alwsOR",
"dk0xrarQzfH6HAdl",
"D1WCkB9jhhPMiuv7",
"zPMj4g6Iu52jXqwq",
"P4OEXKI2FZfFVqVn",
"xMcOFx5m92d9oGQz",
"dkyWq0tLJ8wQknaA",
"iJZUeyjyyn3qQaCT",
"5KhUjwEJK8wIYkoa",
"YB3rEUkE12Pf9hcO",
"qzrzSvzDXukVXvZi",
"Hr1lccIcJZurLKiL", …Run Code Online (Sandbox Code Playgroud) 我有一个 mat-table,我使用以下 css 将标题和单元格居中对齐:
.center-align.mat-header-cell {
display: flex !important;
justify-content: center !important;
padding-left: 18px !important;
}
.center-align.mat-footer-cell {
display: flex !important;
justify-content: center !important;
}
.center-align.mat-cell {
display: flex !important;
justify-content: center !important;
}
.left-align.mat-header-cell {
padding-right: 18px !important;
}
Run Code Online (Sandbox Code Playgroud)
我最终得到的是:我的桌子
这是stackblitz中的代码
我要解决的问题是其中一个列标题(“Amount 9 Column Name”)被包裹。有足够的空间使其他列更窄一些。有没有办法让单元格自动调整一点大小,这样这个标题就不会被包裹?我已经看到其他一些关于手动设置其他列的列宽的帖子,例如:
.mat-column-position {
flex: 0 0 100px;
}
Run Code Online (Sandbox Code Playgroud)
但如果可以的话,我想避免这样做。我不想浏览每一页上的每个表格并调整多列。谢谢。
更新: 我仍然没有解决这个问题,但是如果我将 html 更新为:
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header class="left-align"> Name </th>
<td mat-cell *matCellDef="let element" …Run Code Online (Sandbox Code Playgroud) 我已经看到了很多关于此的问题,但似乎不是我遇到的相同问题。我刚刚创建了我的第二个角度项目。我src/app/employees在employees.component.html中尝试使用的位置下有一个新组件。我得到的错误是:
Uncaught Error: Template parse errors:
'mat-card' is not a known element:
1. If 'mat-card' is an Angular component, then verify that it is part of this module.
2. If 'mat-card' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<mat-card> </mat-card>
Run Code Online (Sandbox Code Playgroud)
现在,在app.module.ts中,我有:
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { LOCALE_ID, NgModule } from "@angular/core";
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http"; …Run Code Online (Sandbox Code Playgroud) 我是Swift和iOS编程的新手,我正在制作一些简单的应用程序.我正在尝试构建一个主 - 详细应用程序.
在主视图中,我给了tableview两个部分,并且我将表视图的内容设置为"静态单元".最初我给每个部分3行,并且能够使用mainviewcontroller文件中的以下代码成功运行应用程序:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
Run Code Online (Sandbox Code Playgroud)
我现在想要在第一部分中有11行,在第二部分中有5行,但我尝试对代码进行的更改会阻止应用程序运行.我试过了:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 16
}
Run Code Online (Sandbox Code Playgroud)
我试过了:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 11
}
Run Code Online (Sandbox Code Playgroud)
但它倒下了.我在这做错了什么?
目前我有以下代码来填充表格。
在 component.ts 中:
import { HttpClient } from "@angular/common/http";
import { Component, OnInit } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router";
import { MatTableDataSource } from "@angular/material/table";
@Component({
styleUrls: ["./styles.scss"],
templateUrl: "./template.html"
})
export class MyRouteData {
employeeInfoTable: object;
constructor(private http: HttpClient) {}
ngOnInit() {
this.http
.get("http://localhost:5000/MyRoute/GetEmployeeInfo")
.subscribe(response => {
this.employeeInfoTable = response;
});
}
}
Run Code Online (Sandbox Code Playgroud)
我的 template.html 文件如下所示:
<mat-card style="height: 98%">
<div style="height: 95%; overflow: auto;">
<table class="MyNiceStyle"> …Run Code Online (Sandbox Code Playgroud) 我有一个页面使用带有可扩展内容的垫表。我需要能够有一个click事件,该事件记录我正在单击的表的行号。
现在,如果我有一个没有可扩展内容的表,则可以在html文件中成功使用以下内容:
<tr mat-row *matRowDef="let row; columns: displayedColumns; let i = index"
(click)="logIndex(i)">
Run Code Online (Sandbox Code Playgroud)
以及组件文件中的以下内容:
logIndex(i)
{
console.log(i);
}
Run Code Online (Sandbox Code Playgroud)
但这不适用于可扩展内容。这是我正在使用的html文件: Stackblitz HTML
其中包含
<tr mat-row *matRowDef="let element; columns: columnsToDisplay;let i = index;"
class="example-element-row"
[class.example-expanded-row]="expandedElement === element"
(click)="expandedElement = element"
(click)="logIndex(i)">
</tr>
Run Code Online (Sandbox Code Playgroud)
并返回“ undefined”。
这是一个简单的例子。在我的实际页面中,我使用MatTableDataSource作为mat-table的数据源。我知道dataSource.filteredData.indexOf(element)在这种情况下我可以使用它来获取行号,但是mat-table也使用mat-sort,对表进行排序仍然会返回原始行号,而不是排序后的行索引。我可以这样做吗?谢谢
我有以下列表和类:
List<MyClass> MyList
public class MyClass
{
public int id { get; set; }
public bool checked { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我也有两个变量:
int idToFind = 1234;
bool newcheckedvalue = true;
Run Code Online (Sandbox Code Playgroud)
我需要做的是搜索列表并找到id等于该值的MyClass对象idToFind.一旦我在列表中有了对象,我就想将类中checked属性的值更改为值的newcheckedvalue值.
LINQ似乎是解决这个问题的方法,我只是无法正确表达.我可以在一个LINQ表达式中执行此操作吗?