当前现有的表如下所示:
id number amount
1 123 30000.00
2 123 15000.00
3 321 45000.00
... ... ...
1000 567 75000.00
Run Code Online (Sandbox Code Playgroud)
现在我想在每个现有行中添加allocated_amount具有默认值的新列amount。
id number amount allocated_amount
1 123 30000.00 30000.00
2 123 15000.00 15000.00
3 321 45000.00 45000.00
... ... ... ...
1000 567 75000.00 75000.00
Run Code Online (Sandbox Code Playgroud)
有可能的?我使用 MySQL Workbench GUI。
我试图写一条指令,限制用户只能在输入文本控件中输入数字字符。
@Directive({
selector: '[numericControl]'
})
export class NumericControlDirective {
contructor(
private el: ElementRef,
) {}
@HostListener('input', ['$event'])
onInput(e: any) {
if (e.which < 48 || e.which > 57) {
e.preventDefault();
}
}
}
Run Code Online (Sandbox Code Playgroud)
用法
<input type="text" placeholder="Volume" numericControl />
Run Code Online (Sandbox Code Playgroud)
但这是行不通的,有人遇到过这个问题吗?
知道我们如何从中获取响应数据吗refetchQueries?我从突变中获取了查询响应数据。
import { gql } from 'apollo-boost';
export const DONE_TASK = gql`
mutation DoneTask($taskId: ID!) {
doneTask(input: {
taskId: $taskId
}) {
task {
id
status
}
}
}
`;
Run Code Online (Sandbox Code Playgroud)
import { gql } from 'apollo-boost';
export const GET_TASKS_BY_STATUS = gql`
query GetTasksByStatus($status: String!) {
getTasksByStatus(status: $status) {
edges {
node {
id
status
description
}
}
}
}
`;
Run Code Online (Sandbox Code Playgroud)
const response = await client.mutate({
mutation: DONE_TASK,
variables: {
taskId: 1
},
refetchQueries: () => …Run Code Online (Sandbox Code Playgroud) 我发现这篇文章对于如何编写批处理文件以自动化django Web服务器启动非常有用.
但问题是,没有激活virtualenv,如何在脚本中的manage.py runserver之前激活它?
我定义这个viewset,我想创建一个返回不同动物的自定义函数species_type叫distinct_species。
class AnimalViewSet(viewsets.ModelViewSet):
"""
This viewset automatically provides `list`, `create`, `retrieve`,
`update` and `destroy` actions.
"""
queryset = Animal.objects.all()
serializer_class = AnimalSerializer
@list_route()
def distinct_species(self, request):
query_set = Animal.objects.values('species_type').distinct()
serializer = self.get_serializer(query_set, many=True)
return Response(serializer.data)
Run Code Online (Sandbox Code Playgroud)
这是我的Animal模特
class Animal(models.Model):
this_id = models.CharField(max_length=25)
name = models.CharField(max_length=25)
species_type = models.CharField(max_length=25)
breed = models.CharField(max_length=25)
....
Run Code Online (Sandbox Code Playgroud)
这是我的 AnimalSerializer
class AnimalSerializer(serializers.ModelSerializer):
class Meta:
model = Animal
fields = (
'this_id',
'name',
'species_type',
'breed',
...
)
read_only_fields = ('id', …Run Code Online (Sandbox Code Playgroud) 我试图在将字典传递给变量时排除某些键。例如。
dict1 = {
'id': 1,
'name' : 'John Woe',
'flag' : True,
'position' : 'Developer'
}
Run Code Online (Sandbox Code Playgroud)
现在我想在将键flag传递给dict2变量时排除该键或任何指定的键。通常我可以简单地硬编码分配它,但我想要一种动态方法。
比如这样:
dict2 = dict1.exclude(['flag', 'position'])
Run Code Online (Sandbox Code Playgroud) 在我的由angular-cli生成的应用程序中,有angular-cli.json一个控制ng操作的文件。
但是,如何排除根目录中指定的src内的某些文件夹?
"apps": [{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}],
Run Code Online (Sandbox Code Playgroud)
我想添加类似的东西,"exclude": [ "folder_name1", "folder_name1" ]但我找不到在此达成共识的任何解决方案。
我正在创建一个细分为不同应用程序的项目。例如,我想使用身份验证应用程序。
首先,让我们定义一下我的意思是一次性全局模块。作为一个最小的例子,这里有几个列表。
FlexLayoutModuleCustomUIModule这些模块必须在项目中声明一次。这里是AppModule
@NgModule({
declarations: [
AppComponent,
],
imports: [
// Dependencies
BrowserModule,
BrowserAnimationsModule,
FlexLayoutModule,
CustomUIModule,
// Apps
AuthenticationModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
现在让我向您展示AuthenticationModule. 我只有这个模块的登录组件。
@NgModule({
declarations: [
LoginComponent,
],
exports: [
LoginComponent
],
})
export class AuthenticationModule { }
Run Code Online (Sandbox Code Playgroud)
我的问题是这里LoginComponent不能识别FlexLayoutModule和CustomUIModulemodules.However这可以解决,如果你把这些模块在输入的选项AuthenticationModule。
但是疯了的人,每当我创建另一个应用程序并做同样的事情时,我都不想这样做,因为这些模块是全局类型并且必须声明一次。任何人都可以有任何解决方案如何构建我的应用程序?非常感谢。
更具体地说,我得到了this error:
Error: Template parse errors:'mat-[some-material-component]'is not a known element.
Run Code Online (Sandbox Code Playgroud) 我有一个可以在控制输入值更改时进行计算的表格。
这是我的form_group样子:
form_group = this.fb.group({
control1: [],
control2: [],
control3: [],
...
control10: [],
});
Run Code Online (Sandbox Code Playgroud)
我可以通过form_group.valueChanges观察来检测所有控件值的变化,并进行计算。但是我想排除一些不需要执行此操作的控件。
但是无论如何,如何不检测特定控件上的更改?
在其中编写a form_group.get('controlN').valueChanges并进行计算非常麻烦。我的表单中有5个或更多控件。
我们如何在mat-nav-list内正确添加辅助按钮?
这是我的示例:
<mat-nav-list>
<h3 matSubheader>This is the listview</h3>
<a mat-list-item [routerLink]="['/detail']">
<span matLine>Title</span>
<button mat-icon-button (click)="onAdd()">
<mat-icon>add</mat-icon>
</button>
<button mat-icon-button (click)="onRemove()">
<mat-icon>delete</mat-icon>
</button>
</a>
</mat-nav-list>
Run Code Online (Sandbox Code Playgroud)
在这段代码中,我希望onAdd()or onRemove()可以单独执行,但是页面随后会导航。
angular ×4
python ×3
django ×2
angular-cli ×1
angular5 ×1
batch-file ×1
graphql ×1
mysql ×1
reactjs ×1
typescript ×1
windows ×1