我需要知道如何按条件动态设置FormControl的选定<option>项<select>。
假设我们有客户有订单。有一个下拉菜单,我们可以在其中选择客户,并根据该客户动态设置订单下拉菜单的选项并选择特定订单。
此外,两个下拉菜单都有一个<option>“(新客户/订单)”,以防还没有客户或订单,因此如果我们在没有客户的情况下路由到该表单,则应在两个下拉菜单中选择此“新”选项菜单。如果我们的客户没有订单,则应在订单下拉菜单中选择“新建”选项。
这是 form.component.html:
<form [formGroup]="customerForm">
<select formControlName="customers">
<option>(new customer)</option>
<option [ngValue]="customer" *ngFor="let customer of customers">
{{customer.name}}
</option>
</select>
<select formControlName="orders">
<option>(new order)</option>
<option [ngValue]="order" *ngFor="let order of filteredOrders">
{{order.id}}
</option>
</select>
</form>
Run Code Online (Sandbox Code Playgroud)
这是 form.component.ts:
customerForm: FormGroup;
customers: Customer[] = [
{ "id": 1,
"name": "Meghan Castellano",
"orderIds": [1,2] },
{ "id": 2,
"name": "Monika Weiss",
"orderIds": [3,4] }];
orders: Order[] = [{"id": 1},{"id": 2},{"id": 3},{"id": 4}];
filteredOrders: Order[];
constructor( private route: ActivatedRoute, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用URL直接从互联网播放M4A(MP4音频)文件.
我正在使用带有MediaFoundation的NAudio来实现这个目的:
using (var reader = new MediaFoundationReader(audioUrl)) //exception
using (var wave = new WaveOutEvent())
{
wave.Init(reader);
wave.Play();
}
Run Code Online (Sandbox Code Playgroud)
这适用于Windows 8.1和Windows 10的两个测试系统.但是在我的Windows 7机器上它无法工作,我从MediaFoundationReader构造函数中获得异常.
最初,我得到了一个ArgumentOutOfRangeException.我测试了在WMP中播放这个m4a文件,它也无法播放它.我下载了一个编解码器包并安装了它.这有助于WMP,但我的代码仍然抛出异常,尽管另一个:
NAudio.dll中发生了未经检查的"System.Runtime.InteropServices.COMException"类型的异常
附加信息:有更多可用数据.(HRESULT异常:0x800700EA)
什么可能导致这个以及我如何解决它?
在 Vue3 中我可以执行以下操作:
父组件:
<ChildComponent :props="{ id: 'the-id', class: 'the-class' }" />
Run Code Online (Sandbox Code Playgroud)
子组件:
<ChildComponent :props="{ id: 'the-id', class: 'the-class' }" />
Run Code Online (Sandbox Code Playgroud)
这将导致 HTML 如下所示:
<template>
<input v-bind="props" />
</template>
<script>
export default {
props: {
props: { type: Object }
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我仍在学习 Vue,我想知道是否可以使用事件侦听器/处理程序做同样的事情。
对于可重用的组件,我可能需要不同的事件侦听器/处理程序,具体取决于我使用该组件的位置。在一种形式中,我可能只需要@input="..."子组件中的一个,在另一种形式中,我可能还需要一个@blur="...",或者我可能根本不需要事件侦听器。
是否可以做类似的事情?
父组件:
<ChildComponent :events="{ input: function() { alert('input!'); }, blur: function() { alert('blur!'); } } />
Run Code Online (Sandbox Code Playgroud)
子组件:
<input id="the-id" class="the-class" />
Run Code Online (Sandbox Code Playgroud)
谢谢 ;)