小编Con*_*ver的帖子

绑定到动态生成的组件/元素的可绑定属性

我正在 aurelia 上开发一个自定义属性,以便用户在输入文本区域时从列表中进行选择。例如,用法将是这样的:

<textarea value.bind="description" placeholder="your description here" auto-complete></textarea>
Run Code Online (Sandbox Code Playgroud)

正如您可能注意到的, theauto-complete是属性。现在,当我想显示提示时,我想在自定义元素中执行此操作以保持简单。所以属性的附加方法将是这样的:

attached() {
    this.containerElement = document.createElement('div');
    this.containerElement.style.position = 'relative';
    const ce = document.createElement('autocomplete-menu');
    this.containerElement.appendChild(ce);
    const ceView = this.templatingEngine.enhance(ce);
    ceView.attached();
    const currentParrent = this.element.parentElement;
    currentParrent.replaceChild(this.containerElement, this.element);
    this.containerElement.appendChild(this.element);
}
Run Code Online (Sandbox Code Playgroud)

现在它打开并成功显示提示区域。屏幕截图:

结果

当我想从属性视图模型生成的元素进行通信时,问题就开始了。例如,我想将数据发送到其视图模型或将某个对象绑定到该对象的可绑定属性。对于这个问题我找到了这些解决方案:

https://discourse.aurelia.io/t/dynamically-add-custom-attribute-to-element/1400/6 https://ilikekillnerds.com/2016/01/enhancing-at-will-using-aurelias-templated -引擎增强-api/

并阅读本文的最后一部分:

https://aurelia.io/docs/binding/how-it-works#abstract-syntax-tree

并发现,我必须为元素的视图模型引入一个对象作为其绑定上下文或覆盖上下文。因此,如果我是对的,我已经测试了以下解决方案:

this.containerElement.appendChild(ce);
let vm = { test: 1 }
const ceView = this.templatingEngine.enhance({ element: ce, bindingContext: vm });
ceView.addBinding(vm);
ceView.attached();
Run Code Online (Sandbox Code Playgroud)

this.containerElement.appendChild(ce);
let vm = { test: 1 }
const ceView = this.templatingEngine.enhance(ce);
ceView.bind(vm); …
Run Code Online (Sandbox Code Playgroud)

data-binding template-engine aurelia

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

ASP Core 2.0 app.UseJwtBearerAuthentication失败

我使用dot net core 1.1开发了一个Web应用程序.它已经工作正常,直到我更新到asp核心2.0.然后,当尝试使用该应用程序时,它会报告此错误:

InvalidOperationException:未指定authenticationScheme,并且未找到DefaultChallengeScheme.

JwtBearerAuthentication的身份验证配置,以前的Configure方法Startup.cs如下:

app.UseJwtBearerAuthentication(new JwtBearerOptions
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge = true,
                TokenValidationParameters = tokenValidationParameters
            });
Run Code Online (Sandbox Code Playgroud)

面对这个错误后,我已经更新了这个:

app.UseJwtBearerAuthentication(new JwtBearerOptions
        {
            AutomaticAuthenticate = true,
            AutomaticChallenge = true,
            TokenValidationParameters = tokenValidationParameters,
            AuthenticationScheme = JwtBearerDefaults.AuthenticationScheme
        });
Run Code Online (Sandbox Code Playgroud)

但仍然是错误消息仍然存在.我错误地找错了地方,或者我必须为身份验证系统添加其他配置吗?

restful-authentication asp.net-core

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

EF Core Tools不适用于dotnet core 3预览版4

我正在尝试使用dotnet core 3 Preview 4开发一些WebAPI。dotnetcore及其库(例如EF core和Identity等)对我很熟悉。但是现在使用版本3 Preview 4,Microsoft.EntityFrameworkCore.Tools无法正常工作,并且该命令dotnet ef migrations add ...告诉此消息:

找不到命令“ dotnet ef”,请运行以下命令进行安装

dotnet工具安装--global dotnet-ef

csproj文件是这样的:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview4-19216-03" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview4.19216.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0-preview4.19216.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview4.19216.3"/>
  </ItemGroup>

</Project>
Run Code Online (Sandbox Code Playgroud)

而且我已经尝试dotnet tool install --global dotnet-ef但没有解决我的问题。随着版本3预览版4的新发布,​​我在官方网站或第三方网站上找不到与此有关的任何文档。

entity-framework command-line-interface .net-core

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

Java 的 AST 差异提取器

假设我有两个这样的源代码:

程序1:

public class MathUtils4M0
{

    public  int getMaxAdjacentSum( int[] numbers )
    {
        if (numbers == null || numbers.length < 2) {
            return 0;
        } else {
            int max = Integer.MIN_VALUE;
            for (int i = 0; i < numbers.length * 1; i++) {
                int temp = numbers[i] + numbers[i + 1];
                if (temp > max) {
                    max = temp;
                }
            }
            return max;
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

程序2:

public class MathUtils4M92
{

    public  int getMaxAdjacentSum( int[] numbers )
    {
        if (numbers …
Run Code Online (Sandbox Code Playgroud)

java diff patch abstract-syntax-tree

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

在ngIf中使用array.prototype.some

我正在使用第8版开发有角度的应用程序。在ngIf表达式内部,我想检查数组中是否存在存在。所以我写了下面的表达式:

*ngIf="questionniare.factors.some(item => item.intensities.length > 0)"
Run Code Online (Sandbox Code Playgroud)

但是现在我在控制台窗口中收到此错误:

解析器错误:绑定不能包含[questionniare.factors.some(item => item.intensities.length> 0)]中第34列的赋值

但是,正如我所见,我的状况没有任何任务。那么有什么问题,我该如何解决?

(我知道我可以定义一个方法并在该方法内完成这项工作,但是我想知道这是否对ngIf有限制,我下次应该考虑一下吗?)

arrays any angular-ng-if angular

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

stale-while-revalidate 缓存策略是什么意思?

我正在尝试使用 ServiceWorker 实现不同的缓存策略。对于以下策略,实施方式是完全明确的:

  1. 先缓存
  2. 仅缓存
  3. 网络优先
  4. 仅限网络

例如,在尝试实现缓存优先策略时,在 service-worker 的 fetch hook 中,我将首先向 CacheStorage(或任何其他)询问请求的 URL,然后如果respondWith它存在,如果不存在respondWith网络请求的结果.

但是对于根据工作箱的这个定义的 stale-while-revalidate 策略,我有以下问题:

  1. 首先是机制本身。stale-while-revalidate 是否意味着使用缓存直到网络响应然后使用网络数据,或者只是使用网络响应来更新您的缓存数据以备下次使用?
  2. 现在,如果网络下次缓存,那么哪些场景包含真正的用例?
  3. 如果应该在应用程序中立即替换网络响应,那么如何在 Service Worker 中完成呢?因为挂钩将使用缓存数据解析,然后无法解析网络数据(使用respondWith)。

caching fetch service-worker service-worker-events

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

具有空闲要求的 Android JobScheduler 不会被解雇

我有一个service扩展JobService如下:

public class MyService extends JobService {
    private int notificationNumber = 0;

    private Thread thread;


    @Override
    public boolean onStartJob(JobParameters params) {
        Toast.makeText(this, "Service1 Started with JobId: " + params.getJobId(), Toast.LENGTH_LONG).show();
        thread = new WorkerThread(this, params);
        thread.start();
        return true;
    }

    @Override
    public boolean onStopJob(JobParameters params) {
        createNotification("Service1 onStop with JobId");
        return false;
    }

    public void createNotification(String msg) {
        notificationNumber++;
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentText(msg);
        builder.setContentTitle("New Notification #" + notificationNumber);
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setAutoCancel(true);

        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); …
Run Code Online (Sandbox Code Playgroud)

service android android-jobscheduler

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