最近我开始研究web pack和react-scripts,我想知道使用它们的优缺点以及它们之间的差异.
我正在使用此链接来实现Typeahead。现在,我使用TypeaheadOptionField在typeahead上显示名称,但它也将名称字符串绑定在模型中。我想绑定对象而不是字符串。
我的HTML代码:
<input formControlName="item" class="form-control" [typeahead]="allItemsArray" [typeaheadItemTemplate]="customItemTemplate"
[typeaheadOptionsLimit]="7" [typeaheadMinLength]="0" [typeaheadOptionField]="name" (typeaheadOnSelect)="onSelectItem($event)">
Run Code Online (Sandbox Code Playgroud)
allItemsArray:
[
{
name: 'a',
code: '12'
},
{
name: 'b',
code: '13'
}
]
Value bound to form control: 'a'
Required value: {'name': 'a', 'code': '12'}
Run Code Online (Sandbox Code Playgroud)
我尝试做的一件事是实现一个事件,该事件将模型值设置为对象,但没有用。
我的 python 代码中有一个重试机制。如果所有尝试都以某种方式失败,我想提出例外
像这样的东西:
last_exc = None
for i in range(3):
try:
raise Exception(i)
except Exception as e:
last_exc = e
else:
raise last_exc
Run Code Online (Sandbox Code Playgroud)
但问题是我没有在日志中得到确切的回溯。我刚刚收到以下消息:
Traceback (most recent call last):
File "snippet.py", line 8, in <module>
raise e
Exception: 2
Run Code Online (Sandbox Code Playgroud)
我期待raise Exception(i)(第 4 行)作为异常中的回溯。该行为仅适用于 python 2.7。
如何设置我正在引发的异常(在上一个异常中引发)的确切回溯?
我尝试使用espeak,但没有成功,并且某些功能仅在python 2中受支持。
我知道这与有关反斜杠的许多其他问题类似,但这涉及到一个尚未解决的特定问题。是否有一种模式可以用来完全消除反斜杠作为打印语句中的转义字符?我需要对ascii艺术了解这一点,因为当所有反斜杠都必须加倍时,很难找到正确的位置。
print('''
/\\/\\/\\/\\/\\
\\/\\/\\/\\/\\/
''')
\```
Run Code Online (Sandbox Code Playgroud) 我有这个错误,可以循环遍历一个数组,但我不知道该怎么做。但我试图插入0代替p1,p2和p3。那行得通。但是如果我运行这段代码。
该程序要做的是对两个数组进行排序,并以正确的顺序设置它们。
Arr2 = [2,5,6,8]
Arr1_Length = len(Arr1)
Arr2_Length = len(Arr2)
FinishArr_Length = Arr1_Length + Arr2_Length
FinishArr = []
p1 = 0
p2 = 0
p3 = 0
print(FinishArr)
print(FinishArr_Length)
print(Arr1[p1])
print(Arr2[p2])
while p3 < FinishArr_Length:
if Arr1[p1] < Arr2[p2]:
FinishArr.append(Arr1[p1])
p1 += 1
else:
FinishArr.append(Arr2[p2])
p2 += 1
p3 += 1
print(FinishArr)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Traceback (most recent call last):
File "Test.py", line 21, in <module>
if Arr1[p1] < Arr2[p2]:
IndexError: list index …Run Code Online (Sandbox Code Playgroud) 我有一些这样的代码:
go func(ch chan bool) chan bool {
// some processing
ch <- true
return ch
}(ch)
for i := 0; i < TotalQuestions; i++ {
// check if channel ch has some value
// If it has then execute below statements, else break out of the loop
fmt.Println(questions[i])
answer, _ := InputReader.ReadString('\n')
// some processing
}
fmt.Println("Your Total score is " + strconv.Itoa(TotalScore) + " out of " + strconv.Itoa(TotalQuestions))
Run Code Online (Sandbox Code Playgroud)
现在我想做的是检查通道 ch 是否有值(在 for 循环中)。如果它有一个值,那么我想跳出 for 循环来打印最后一条语句。否则,我想继续我的循环。我尝试插入选择块,但这不起作用(通道被阻止并且代码没有打印问题)。怎么做?
我有一个 *ngFor 循环,它在屏幕上显示所有材料卡(MatCard 或 mdCard,如果您使用的是旧版本)。当我单击任何 MatCard 时,会打开一个对话框。我想将材料卡的数据插入到对话框中。
这是我的 buyComponent.html
<div *ngIf="allItems" class="layout-row" >
<mat-card *ngFor="let item of allItems" class="flex-lg-20" (click)="OnMatCardClickEvent($event)">
<mat-card-header class="flex-lg-20">
<h2>{{item.itemName}}</h2>
<br>
</mat-card-header>
<mat-card-content class="flex-lg-20">
<h2> </h2>
<br>{{item.itemImageUrl}}
</mat-card-content>
<mat-card-content align="bottom" class="flex-lg-20">
<div>Rs. {{item.itemPrice}}</div>
</mat-card-content>
</mat-card><br><br><br>
Run Code Online (Sandbox Code Playgroud)
这是我的 BuyComponent.ts
@Component({
selector: 'app-buy',templateUrl: './buy.component.html',
styleUrls: ['./buy.component.css']
})
export class BuyComponent implements OnInit {
constructor(private sellItemService: SellItemService,
private dialog:MatDialog) {
}
areThereItems: boolean = false;
allItems: DialogItem[] = [];
ngOnInit() {
this.showAllItemDialogs();
}
OnMatCardClickEvent(){
let dialogRef = this.dialog.open(ItemDialogComponent, {
height: '400px', …Run Code Online (Sandbox Code Playgroud) 假设我有一个像这样的对象数组:
let x = [{'a': 0.288888, 'b': 0.5}, {'a':9.565464645654, 'b': 0.6}];
Run Code Online (Sandbox Code Playgroud)
我想迭代这个并将数字更改为固定长度。我试过
x.map((data) => data.a.toFixed(3))
# ["0.289", "9.565"]
Run Code Online (Sandbox Code Playgroud)
预期输出:
[{'a': 0.289, 'b': 0.5}, {'a':9.565, 'b': 0.6}]
Run Code Online (Sandbox Code Playgroud)
使其发挥作用的一种方法是:
x.map((data) => {
data.a = data.a.toFixed(3);
return data;
});
Run Code Online (Sandbox Code Playgroud)
还有比这更好的方法吗?
python ×3
angular ×2
algorithm ×1
babel ×1
backslash ×1
channel ×1
exception ×1
go ×1
goroutine ×1
iteration ×1
javascript ×1
mergesort ×1
nonblocking ×1
python-2.7 ×1
python-3.x ×1
typeahead ×1
webpack ×1