小编Sam*_*our的帖子

从另一个js文件导入函数.使用Javascript

我有一个关于在javascript中包含文件的问题.我有一个非常简单的例子:

--> index.html
--> models
      --> course.js
      --> student.js
Run Code Online (Sandbox Code Playgroud)

course.js:

function Course() {
    this.id = '';
    this.name = '';
}
Run Code Online (Sandbox Code Playgroud)

学生有课程.像这样:

import './course';

function Student() {
    this.firstName = '';
    this.lastName = '';
    this.course = new Course();
}
Run Code Online (Sandbox Code Playgroud)

和index.html是这样的:

<html>
    <head>
        <script src="./models/student.js" type="text/javascript"></script>
    </head>
    <body>
        <div id="myDiv">
        </div>
        <script>
        window.onload= function() {
            var x = new Student();
            x.course.id = 1;
            document.getElementById('myDiv').innerHTML = x.course.id;
        }
        </script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

但我在"var x = new Student();"行上收到错误:

学生没有定义

当我从学生中删除导入时,我不再收到错误.我曾尝试使用(要求,导入,包含,创建自定义函数,导出),但没有一个对我有用.

谁知道为什么?以及如何解决这个问题?

PS路径正确,它来自VS Code中的自动完成

javascript import

20
推荐指数
4
解决办法
7万
查看次数

在 Entity Framework Core 3 中添加两个表达式来创建谓词不起作用

我正在尝试在 .NET Core 应用程序中使用 C# 和 Entity Framework Core 3 构建“And”谓词方法。

该函数将两个表达式相加,并将其传递给 IQueryable 代码:

public Expression<Func<T, bool>> AndExpression<T>
                    (Expression<Func<T, bool>> left, Expression<Func<T, bool>> right)
{
      var andExpression = Expression.AndAlso(
           left.Body, Expression.Invoke(right,
           left.Parameters.Single()));

      return Expression.Lambda<Func<T, bool>>(andExpression, left.Parameters);
}
Run Code Online (Sandbox Code Playgroud)

函数的调用

Expression<Func<Entity, bool>> left = t => t.Id == "id1";
Expression<Func<Entity, bool>> right = t => t.Id == "id2";
var exp = AndExpression(left, right);
this.dbContext.Set<Entity>().source.Where(exp).ToList();
Run Code Online (Sandbox Code Playgroud)

我的代码在 EF Core 2 版本中运行良好,但在我将版本更新到版本 3 后,它抛出以下异常

LINQ 表达式 'Where( source: DbSet, predicate: (s) => (t => t.Id …

c# expression entity-framework-core

6
推荐指数
1
解决办法
3819
查看次数

web.config asp.net mvc 5 中的 serilog AppSetting

我正在研究 Serilog asp.net MVC 5。一切正常,但我想将设置移动到 web.config 而不是代码。我需要移动数据库连接,文件路径。并且我还必须指定两个不同的级别,一个用于数据库,另一个用于文件。

这是代码

 var logFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"xxx.Web-{Environment.MachineName}.log");
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.Trace(LogEventLevel.Debug, "{Timestamp:u} [{Level}] {SourceContext}:: {CorrelationId} {Message}{NewLine}{Exception}")
                .WriteTo.LiterateConsole(LogEventLevel.Debug, "{Timestamp:u} [{Level}] {SourceContext}:: {CorrelationId} {Message}{NewLine}{Exception}")
                .WriteTo.RollingFile(logFileName, LogEventLevel.Debug,
                    "{Timestamp:u} [{Level}] {MachineName} {SourceContext}:: {CorrelationId} {Message}{NewLine}{Exception}",
                    retainedFileCountLimit: 31, fileSizeLimitBytes: null)
                .WriteTo.MSSqlServer(connectionString, "LogUsers", LogEventLevel.Information)
                .Enrich.WithExceptionDetails()
                .Enrich.With<HttpRequestIdEnricher>()
                .Enrich.FromLogContext()
                .CreateLogger();
Run Code Online (Sandbox Code Playgroud)

PS connectionString 变量来自 web.config。

我对 serilog 很陌生,所以我真的很困惑。请尽快重播。

谢谢你

asp.net asp.net-mvc appsettings serilog

4
推荐指数
1
解决办法
5852
查看次数

serilog appSettings在同一服务器路径asp.net mvc中写入文件

我有一个serilog代码,我想将配置移动到web.config文件.

一切正常,但问题是文件的路径:

var logFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"EnBW.DokumentErfassung.Web-{Environment.MachineName}.log");
    Log.Logger = new LoggerConfiguration()
                        .ReadFrom.AppSettings();
Run Code Online (Sandbox Code Playgroud)

我想在同一服务器路径中写入新文件,web.config代码是:

<add key="serilog:using:RollingFile" value="Serilog.Sinks.RollingFile" />
    <add key="serilog:write-to:RollingFile.pathFormat" value="log123-{Date}.txt" />
Run Code Online (Sandbox Code Playgroud)

但保存的文件已保存在C:/ program file/.....

我希望它保存在相同的域路径中.我该怎么办?

asp.net-mvc file appsettings serilog

4
推荐指数
1
解决办法
2264
查看次数

在特定列内写入 Serilog ASP.NET MVC C#

我正在使用 C# 在 ASP.NET MVC 中处理 Serilog。

我必须记录日志类型,一种用于管理员级别,一种用于用户级别。

我想创建一个名为“角色”的额外列,根据微软会员资格,包含 1 个管理员或 2 个用户。

我使用了这段代码:

string connectionString = ConfigurationManager.........;

            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.MSSqlServer(connectionString, "Logs")
                .Enrich.WithExceptionDetails()
                .Enrich.With<HttpRequestIdEnricher>()
                .Enrich.FromLogContext()
                .CreateLogger();

            Log.Information("Web4 starting");
            Log.Information("log location: {0}", AppDomain.CurrentDomain.BaseDirectory);
Run Code Online (Sandbox Code Playgroud)

我已经将该列添加到数据库中

创建列后如何写入?

c# asp.net asp.net-mvc serilog

3
推荐指数
1
解决办法
3540
查看次数

Angular 4中KendoUI的替代方案

我正在使用以下项目:

  1. Web API 2
  2. Angular 4

我想为GUI选择一个框架.我想到了"Teleular KendoUI for Angular",这真的是一个很好的lib.但Bootstrap 4是唯一受此版本Kendo支持的版本.我的公司有一个Bootstrap 3设计,所以他们不想改变它.

问题是:是否有任何其他Lib用于GUI,如KendoUI我们可以使用它们吗?或者是否有工具或东西将文件从Bootstrap 3转换为Bootstrap 4?谢谢.

kendo-ui bootstrap-4 angular

3
推荐指数
1
解决办法
4365
查看次数

ngFor Angular2中的动态管道

我正在编写Angular4应用程序。我有一个包含值和管道类型的数组。(地区,语言或号码)

const values = [
   { value: 'us', pipe: 'regions'},
   { value: 'en', pipe: 'language'},
   { value: '100', pipe: 'number'},
.....
];
Run Code Online (Sandbox Code Playgroud)

我想制作一个ngFor,以便我可以显示值并应用正确的管道:(类似这样)

<li *ngFor="let item of values"> {{item.value | item.pipe}} </li>
Run Code Online (Sandbox Code Playgroud)

我试图建立一个类:

export class FacetConfiguration {
  value: string;
  pipe: Pipe;
}
Run Code Online (Sandbox Code Playgroud)

然后将管道的对象注入类。但是没有用。

有这种方法吗?或其他想法?

PS我这样做的原因是,我有大量的配置列表,并且每个配置都有不同的管道类型,因此硬编码会很困难。

谢谢

pipe typescript angular

3
推荐指数
1
解决办法
1751
查看次数

将服务器名称声明为MS Sql Server 2016中的变量

我的脚本文件很大,需要在另一台服务器上使用。我需要在开始时使用Declare编辑服务器的名称,以便仅通过更改变量的值就可以在多个服务器上使用相同的脚本。

像这样的东西:

Declare @Quell nvarchar(100)
SET @Quell = '[server1].[dbo]'

SELECT * From @Quell.[Documents] 
Run Code Online (Sandbox Code Playgroud)

但是没有用。

怎么做?谢谢

sql sql-server declare server-name

2
推荐指数
1
解决办法
3051
查看次数

Web API 2中的Google reCaptcha c#

我有一个ASP.NET Web API 2项目.我试图从表单中读取Google Captcha.我试过这个代码:

    public string Post(FoundingRequest model)
    {
        var response = Request["g-recaptcha-response"];
        string secretKey = "my key";
        var client = new WebClient();
        var result = client.DownloadString(
        $"https://www.google.com/recaptcha/api/siteverify?secret={secretKey}&response={response}");
        var obj = JObject.Parse(result);
        model.Captcha = (bool)obj.SelectToken("success");
        ....
    }
Run Code Online (Sandbox Code Playgroud)

但我在第一行收到错误:

无法将带有[]的索引应用于类型为"HttpRequestMessage"的表达式

为什么?以及如何解决?谢谢

c# recaptcha asp.net-web-api asp.net-web-api2

2
推荐指数
2
解决办法
4859
查看次数

Angular 库无法导出类 - Angular6

我创建了一个新的 Angular 6 库。这个库有一个名为 User 的模型:

export class User {
    public id: string;
    public username: string;

    constructor(id: string,
                username: string) {
        this.id = id;
        this.username = username;
    }
}
Run Code Online (Sandbox Code Playgroud)

我在另一个角度应用程序中使用该库,一切正常。但是当我尝试使用模型时:

export class AppComponent {
  public user: User;

  constructor() {
    this.user = new User('1', 'my user');
  }
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Module not found: Error: Can't resolve 'my-lib/lib/models/user.model' in 'C:\my-app\src\app'
Run Code Online (Sandbox Code Playgroud)

智能感知找到了它,但我仍然收到此错误。

应用模块:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    UserModule,
  ],
  bootstrap: [AppComponent]
})
Run Code Online (Sandbox Code Playgroud)

有人有想法吗?谢谢!

model angular-library angular6

2
推荐指数
1
解决办法
2136
查看次数

如何使用我的自定义方法扩展控制器类

我想从扩展控制器类轻松获取我的方法,并向控制器类添加一些方法以在所有其他控制器中使用,如下所示:

扩大

public string GetString()
{
    return "iamanexample";
}
Run Code Online (Sandbox Code Playgroud)

认证控制器

public class AuthenticationController : Controller
{
   public IActionResult Index()
   {
       string getMyStr = GetString();
       return View();
   }
}
Run Code Online (Sandbox Code Playgroud)

我是否必须创建一个由控制器类继承的自定义类并在其中添加我的方法,然后使用我的自定义控制器类?或者还有其他解决方案吗?

c# asp.net asp.net-core

1
推荐指数
1
解决办法
6177
查看次数