问题描述
我在Asp.net锅炉模板项目上创建了一个简单的表单。我一共有三个领域
在Table 1
在Table2
- 带有产品列表的标签
我想将第三字段数据存储在数据库的另一个表中。 但是我是个初学者,很困惑。 产品名称和数量工作正常。有人可以指导我吗?为什么第二张表中的数据存储为空?
(1) This is chips code ( from priming)
(2) This is my class code (in which all three data members exist
(3) This is my Product list class code for storing chips
(4) This is database table of Product
(5) This is Database table of Product list class
import {Component,Injector,OnInit,EventEmitter,Output,} from '@angular/core';
import { finalize } from 'rxjs/operators';
import { BsModalRef } from 'ngx-bootstrap/modal';
import * as _ from 'lodash';
import { AppComponentBase } from '@shared/app-component-base';
import {
ProductServiceProxy,ProductDto,Product_listDto,Product_listServiceProxy
} from '@shared/service-proxies/service-proxies';
@Component({
templateUrl: 'create-product.component.html'
})
export class CreateProductComponent extends AppComponentBase
implements OnInit {
saving = false;
product = new ProductDto();
@Output() onSave = new EventEmitter<any>();
constructor(
injector: Injector,private _productService: ProductServiceProxy,public bsModalRef: BsModalRef
) {
super(injector);
}
ngOnInit(): void {
}
save(): void {
this.saving = true;
console.log("input",this.product)
const product = new ProductDto();
product.init(this.product);
this._productService
.create(product)
.pipe(
finalize(() => {
this.saving = false;
})
)
.subscribe(() => {
this.notify.info(this.l('SavedSuccessfully'));
this.bsModalRef.hide();
this.onSave.emit();
});
}
}
解决方法
您的p-chip
返回一个字符串数组,但是您的后端需要一个product_list
对象。您需要将一个'product_list'对象数组传递给后端。
save(): void { this.saving = true; console.log("input",this.product) let productList = [...this.product.productList]; this.product.productList = productList.map(item=>{ return { Id: 0,Name: item } }); const product = new ProductDto(); product.init(this.product); }