小编idu*_*ude的帖子

如何在网页上显示控制台输出?

当我访问 Codecademy 或 JSBin 等网站时,我注意到它们允许您查看控制台输出。这是如何运作的?

只是为了澄清,假设用户在文本框中键入此内容

console.log('hello');
Run Code Online (Sandbox Code Playgroud)

如何在实际网页上输出而不是在浏览器的控制台上输出?

javascript console jsbin console.log

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

有没有办法将这两种方法结合起来?

目前我正在创建一种方法来反转java中的链表,但它需要两种方法:

public void reverse(){
    reverse(head);
}

private void reverse(Node h){
    if(h.next==null){
        System.out.print(h.data+" ");
        return;
    }

    reverse(h.next);
    System.out.print(h.data+" ");   
}
Run Code Online (Sandbox Code Playgroud)

这样我用0参数调用reverse方法,然后调用另一个反向方法.有没有办法让他们1方法而不改变我的LinkedList类的其他方面?

提前致谢!

java methods overloading linked-list data-structures

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

在没有innerHTML的情况下更改JavaScript中的HTML

假设我的代码非常简单,如下所示:

let content = "";

for(let i=0; i<array.length; i++){
    content+='<h1>array[i]</h1>';
}

document.getElementById('some_id').innerHTML = content;
Run Code Online (Sandbox Code Playgroud)

我不喜欢将 HTML 放入 JavaScript 代码中的想法,但我不知道在不使用innerHTMLJQueryhtml()方法或简单地以编程方式创建新 DOM 元素的情况下将元素插入 DOM 的任何其他方法。

在行业中或最佳实践中,从 JavaScript 插入 HTML 元素的最佳方法是什么?

提前致谢!

html javascript dom innerhtml

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

“找不到类型或命名空间‘BlobTrigger’”

所以我是 C# 中 Azure 函数的新手,我正在尝试使用 BlobStorage 触发器在 Visual Studio 中创建。在遵循模板时,我得到了一个看起来像这样的文件:

using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host.Triggers;
using Microsoft.Extensions.Logging;

namespace BasicAzureFunction
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([BlobTrigger("samples-workitems/{name}", Connection = "")]Stream myBlob, string name, ILogger log)
        {
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我总是收到这个错误:

The type or namespace name 'BlobTriggerAttribute' could not be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)

我很确定我有所有的包(这实际上是模板)。我错过了什么?

使用 .Net …

c# compiler-errors azure .net-core azure-functions

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

使用 Azure Functions 进行 ILogger 依赖注入

因此,我尝试使用依赖注入设置 ILogger,但遇到了一些麻烦。

在我的startup.cs文件中,我有一些看起来像这样的东西:

        builder.Services.AddLogging();
Run Code Online (Sandbox Code Playgroud)

然后,我尝试将该记录器提供给我自己的类(它的作用就像 ILogger 库的包装器)

    builder.Services.AddSingleton<LoggingWrapper>(s =>
    {
        return new LoggingWrapper(
            s.GetService<ILoggerFactory>());
    });
Run Code Online (Sandbox Code Playgroud)

因此,在我的 Azure 函数中,LoggingWrapper被注入内部,但它不会记录任何内容。每个函数附带的普通 ILogger 仍然可以工作,但我想知道为什么我的包装器没有记录任何内容。

Logging Wrapper 是一个类,它采用 ILogger 方法并使用它来创建自己的日志记录方法。例如loggingWrapper.logInformation("string"),有一个方法可以包装`ILogger.

我将其注入到我的其他类中,如下所示:s.GetService<ILoggerFactory>()

预先感谢您的所有帮助!

c# dependency-injection azure azure-functions ilogger

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

java的Prime编号程序

我是编程新手,需要java程序的帮助.我希望我的程序返回1到10之间的所有素数.

    for(int i=1; i<=10; i++){
        int factors = 0;
        int j=1;

        while(j<=i){
            if(i % j == 0){
                factors++;
            }
            j++;
        }
        if(factors==2){
            System.out.println(j);
        }
    }
Run Code Online (Sandbox Code Playgroud)

我没有收到2,3,5和7,而是收到3,4,6和8

java primes numbers logic-programming

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

导航栏,标题在中心,按钮在右边

所以我试图创建一个导航栏,中间有一个标题,一个按钮出现在右侧。如您所见,当我尝试执行此操作时,按钮出现在下一行和 div 之外:

小提琴

.title-bar {
  background-color: #48A6B8;
  font-style: italic;
  margin-bottom: 3%;
  color: #fff;
}

.title {
  text-align: center;
  font-size: 36px;
  line-height: 180%;
}

.buts {
  float: right;
}
Run Code Online (Sandbox Code Playgroud)
<div class="title-bar">
  <div class="title">Title</div>
  <div class="button">
    <button class="buts">Whats Up</button>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

display:inline-block 似乎删除了文本的居中,所以我不能使用它......

提前致谢!

html css navbar display

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

Task.WhenAll but 一一处理结果

假设我有一个任务列表,我想并行运行它们。但是我不需要所有这些都完成才能继续,我可以只做一个。以下代码等待所有任务完成才能继续。有没有办法让我在等待其他任务完成的同时单独继续完成已完成的任务?

List<string>[] x = await Task.WhenAll(new Task<List<string>>[] { task1, task2 })
// when task1 finishes, I want to process the result immediately instead of waiting on task2.
Run Code Online (Sandbox Code Playgroud)

提前致谢!

c# task task-parallel-library

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

1&1无法找到Heroku应用程序的CNAME

我在[myapp] .herokuapp.com上运行了一个heroku应用程序,我在[name] .com到1&1有一个域名

我希望我的1&1域名重定向到我的heroku应用程序,但我似乎无法使CNAME正确.每当我输入[myapp] .heroukapp.com作为我在1和1的别名时,它表示它是无效的主机名.我该怎么做才能解决这个问题?

dns alias cname heroku node.js

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

Rails- Ruby实例变量

所以我使用omniauth-facebook使用Facebook创建登录.
这是我的sessions_controller.rb

class SessionsController < ApplicationController

  def create
    user = User.from_omniauth(env["omniauth.auth"])
    session[:user_id] = user.id
    redirect_to "/sessions/menu"
  end

  def destroy
    session[:user_id] = nil
    redirect_to root_url
  end

  def new
  end

  def menu
      puts user.name
  end

end
Run Code Online (Sandbox Code Playgroud)

不幸的是我不知道如何在菜单操作中访问用户变量.你们怎么建议我这样做?

更新

class SessionsController < ApplicationController

  def create
    @user = User.from_omniauth(env["omniauth.auth"])
    session[:user_id] = @user.id
    redirect_to "/sessions/menu"
  end

  def destroy
    session[:user_id] = nil
    redirect_to root_url
  end

  def new
  end

  def menu
      puts @user
  end

end
Run Code Online (Sandbox Code Playgroud)

即使我像这样更新它,它也行不通

ruby variables facebook ruby-on-rails omniauth

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

活动函数需要当前时间 - Azure Functions

所以我有一个持久功能,看起来像这样:

    [FunctionName("functionName")]
    public async Task functionName([OrchestrationTrigger] IDurableOrchestrationContext context)
    {
       // some code here
       string name = "name";
       await context.CallActivityAsync("activityFunction", name);
    }

    [FunctionName("activityFunction")]
    public async Task ActivityFunction([ActivityTrigger] IDurableActivityContext name)
    {
        // perform an operation here
        // need to get current UTC time here
    }
Run Code Online (Sandbox Code Playgroud)

无法从活动上下文中获取当前 UTC 时间。我该如何得到它?

c# azure azure-functions azure-durable-functions

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

如何在变量中存储iframe?

<html>
<body>
   <iframe id="src">

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我希望iframe通过Javascript函数显示在div元素中,但我似乎无法弄清楚什么是无效的.有任何想法吗?

document.getElementById('site').src = http://www.w3schools.com/;
Run Code Online (Sandbox Code Playgroud)

提前致谢!

javascript iframe

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