这是我的代码,在项目中广泛使用,我想知道我可以以某种方式重构它,这样我就可以一直避免== null
检查吗?
ActiveCompany = admin.Company == null ? false : admin.Company.Active
Run Code Online (Sandbox Code Playgroud)
多谢你们
干杯
我正在做一个小的角度项目。我有一系列的收据项目,例如可乐,fanta,百事可乐,果汁等,当然还有它们的价格和数量。
receiptItems: Array<ReceiptItem>;
Run Code Online (Sandbox Code Playgroud)
ReceiptItem
看起来是这样的:
export class ReceiptItem {
public id: string;
public product: Product;
public unitOfMeasure: UnitOfMeasure;
public discount: number;
public price: number;
public quantity: number;
public total: number;
public tax:Tax;
}
Run Code Online (Sandbox Code Playgroud)
我如何才能在打字稿中获得总额的总和,但是仅在例如财产税等于“ 25%”的情况下?
我记得在C#中我使用过如下的lambda表达式:
IEnumerable<ReceiptItems> results = receiptItems.Where(s => s.Tax == "25.00");
totalSum = results.Sum(x => (x.TotalAmount));
Run Code Online (Sandbox Code Playgroud)
如何在TypeScript / Angular中实现类似的功能?
我工作的WPF C#应用程序,我需要检测,当用户按下“ / ”,但我在使用寻找麻烦“ / ” e.Key,我看到有Key.OemBackslash
和这样的东西,但我不能正确找到“ / ”(正斜杠)的事件...
谢谢各位,干杯
我有一个场景,我必须使用 .NET CORE WEB API PROJECT 扩展我的项目。
一开始它只是控制台应用程序,它作为 Windows 服务执行简单的任务,将 xml 文件中的数据添加到数据库。
我的结构如下所示:
现在,当我创建 WEB API 项目时,它要求我在 Startup.cs 中注册 Context,我是这样做的:
启动.cs
// DbContext for MSSQL
services.AddDbContextPool<ProductXmlDBContext>(options => options.UseSqlServer(_configuration.GetConnectionString(Config.CONNECTION_STRING)));
Run Code Online (Sandbox Code Playgroud)
这一切都很好。
但现在我想读取控制台应用程序的连接字符串,因为它有自己的连接字符串(appsettings.json
),因为当我创建 API 时,它有自己的appsettings.json
连接字符串,我在其中存储 WEB API 的连接字符串。
我的 DBContext 看起来像这样:
public ProductXmlDBContext()
{
}
// I added this because it was required for WEB API to work
public ProductXmlDBContext(DbContextOptions<ProductXmlDBContext> options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=localhost;Database=ProductXml;Trusted_Connection=True;");
}
Run Code Online (Sandbox Code Playgroud)
在我的控制台应用程序中我添加了appsettings.json …
我正在从服务中获取数据,我对订阅后取消订阅很重要,这是我的做法:
export class RItemComponent implements OnInit {
apiPath = environment.apiUrl;
private ngUnsubscribe: Subject = new Subject();
constructor(private _sharedService: SharedService) { }
rItems: Product[];
ngOnInit() {
this._sharedService.
getReceiptItem().takeUntil(this.ngUnsubscribe).
subscribe(products => this.rItems = products);
}
ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
}
Run Code Online (Sandbox Code Playgroud)
但是现在我得到一个错误:
泛型类型Subject需要1个类型参数。订阅
我不明白为什么?
任何帮助都会很棒,谢谢!
我想知道如何防止用户选择高于今天日期的日期。例如,今天是 3.7,所以让它成为用户可以选择的最高结束日期。
<DateRangePicker
startDate={this.state.startDate}
startDateId="startDate"
endDate={this.state.endDate}
endDateId="endDate"
onDatesChange={({ startDate, endDate }) => {
this.setState({ startDate, endDate }, () => {});
}}
focusedInput={this.state.focusedInput} // PropTypes.oneOf([START_DATE, END_DATE]) or null,
onFocusChange={focusedInput => this.setState({ focusedInput })} // PropTypes.func.isRequired,
daySize={50}
noBorder={true}
isOutsideRange={() => false}
/>
Run Code Online (Sandbox Code Playgroud) 我正在从服务器下载文件。我在那里设置一个我想在前端读取的文件名。这是我在服务器上执行此操作的方法:
string fileName = "SomeText" + DateTime.UtcNow.ToString() + ".csv";
return File(stream, "text/csv", fileName);
Run Code Online (Sandbox Code Playgroud)
基本上我会返回不同类型的文件,有时csv
有时xlsx
有时pdf
。所以我想在前端获取文件名,以便我可以将其保存为应有的格式,例如SomeText.pdf
它将自动保存在本地计算机上作为pdf
.
这是我的前端代码:
getFileFromServer(params).then(response => {
console.log('server response download:', response);
const type = response.headers['content-type'];
const blob = new Blob([response.data], { type: type, encoding: 'UTF-8' });
//const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'file.xlsx'; // Here I want to get rid of hardcoded value instead I want filename from server
link.click();
link.remove(); // …
Run Code Online (Sandbox Code Playgroud) 我正在从控制器返回一个文件WebAPI
。标Content-Disposition
头值会自动填充,并且还包含我的文件名。
我的后端代码如下所示:
[HttpGet("Download")]
public async Task<ActionResult> Download([FromQuery]CompanySearchObject req)
{
string fileName = "SomeFileName_" + DateTime.UtcNow.Date.ToShortDateString() + ".csv";
var result = await _myService.GetData(req);
Stream stream = new System.IO.MemoryStream(result);
return File(stream, "text/csv", fileName.ToString());
}
Run Code Online (Sandbox Code Playgroud)
在我的前端:
exportData(params).then(response => {
console.log(response);
console.log('Response Headers:', response.headers);
const type = response.headers['content-type'];
const blob = new Blob([response.data], { type: type, encoding: 'UTF-8' });
//const filename = response.headers['content-disposition'].split('"')[1];
//alert(filename);
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'file.xlsx';
link.click();
link.remove();
});
};
Run Code Online (Sandbox Code Playgroud)
但我正在努力获取这些数据,因为当我在前端执行 console.log …
在我的功能组件的顶部,设置了这些值,这些值不仅在样式中使用,这让我感到困扰:
const testWidth = 100;
const testHeight = 100;
Run Code Online (Sandbox Code Playgroud)
我在自己的样式中使用了其中一些变量...
我想将样式移动到另一个文件,该文件将保留此样式并与某些类名相关,例如'。divWrapperStyle
'但我不确定如何与该变量交互' testWidth
'
<div
style={{
borderBottom: 0,
width: `${testWidth}px`,
width: 'auto',
paddingRight: 0,
paddingLeft: 0,
paddingTop: 20,
}}
>
Run Code Online (Sandbox Code Playgroud)
因此,我可以在外部.scc
文件中创建如下内容:
.wrapper{
borderBottom: 0,
paddingRight: 0,
paddingLeft: 0,
paddingTop: 20,
}
Run Code Online (Sandbox Code Playgroud)
导入该文件后,我可能会使用类似的内容:
<div className="wrapper>
Run Code Online (Sandbox Code Playgroud)
但是宽度呢?我如何在testWidth
变量中包含宽度值?
因此,CSS中使用的变量对我来说是有问题的:/
该如何处理?
谢谢
我有两份清单,一份是原始的,一份是复制的。我复制了原始列表,原因如下:
我需要处理/工作原始列表中的数据,但我不应该编辑它。因此,我创建了原始列表的副本以供使用。但不知何故,我对复制列表所做的更改仍然会修改原始列表。
这是我的代码:
forPrintKitchenOrders = new List<OrderTemp>();
foreach (var itemss in forPrintKitchen)
{
forPrintKitchenOrders.Add(itemss); // HERE I AM ADDING ITEMS TO ANOTHER LIST BECAUSE I DON'T WANT TO EDIT ORIGINAL LIST (Change quantity etc)
}
if (forPrintKitchen.Count > 0)
{
foreach (var item in forPrintKitchenOrders.ToList())
{
foreach (var item2 in mainList)
{
if (item2.MainProductID == Convert.ToInt32(item._articleCode))
{
//I don't know why this is happening. I loop another list (copy of original list, because I didn't want to harm original list), …
Run Code Online (Sandbox Code Playgroud) c# ×6
javascript ×4
reactjs ×4
asp.net-core ×3
html ×2
typescript ×2
.net-core ×1
angular ×1
css ×1
date-range ×1
dbcontext ×1
httpresponse ×1
key ×1
list ×1
math ×1
null ×1
rxjs ×1
slash ×1
wpf ×1