小编Bal*_*ázs的帖子

将D3.js与Angular 2一起使用

我已成功将Angular 2(Alpha 44)与D3.js集成:

<html>
<head>
<title>Angular 2 QuickStart</title>
<script src="../node_modules/systemjs/dist/system.src.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
<script>
  System.config({packages: {'app': {defaultExtension: 'js'}}});
  System.import('app/app');
</script>
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

app.js:

/// <reference path="./../../typings/tsd.d.ts" />

import {Component, bootstrap, ElementRef} from 'angular2/angular2';

@Component({
  selector: 'my-app',
  template: '<h1>D3.js Integrated if background is yellow</h1>',
  providers: [ElementRef]
})
class AppComponent { 
  elementRef: ElementRef;

  constructor(elementRef: ElementRef) {
   this.elementRef = elementRef;
  }

afterViewInit(){
    console.log("afterViewInit() called");
    d3.select(this.elementRef.nativeElement).select("h1").style("background-color", "yellow");
  }
}
bootstrap(AppComponent);
Run Code Online (Sandbox Code Playgroud)

一切都很好.但是ElementRef的Angular 2文档说明如下:

当需要直接访问DOM时,请使用此API作为最后的手段.请使用Angular提供的模板和数据绑定.或者,您可以查看{@link Renderer},它提供了可以安全使用的API,即使不支持直接访问本机元素也是如此.依赖于直接DOM访问会在应用程序和渲染层之间产生紧密耦合,这使得无法将两者分开并将应用程序部署到Web工作者中.

现在问题是如何将D3.js与Renderer API集成?

d3.js angular

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

将客户端证书添加到.net核心Httpclient

我正在玩.Net Core并构建一个利用支付API的API.需要将客户端证书添加到双向SSL身份验证请求中.如何使用HttpClient在.Net Core中实现这一目标?

我查看了各种文章,发现HttpClientHandler没有提供添加客户端证书的任何选项.

请指教

.net c# dotnet-httpclient .net-core asp.net-core

39
推荐指数
4
解决办法
5万
查看次数

如何使用EntityFramework调用存储过程?

我已经从MySQL数据库生成了EF4模型,并且我已经包含了StoredProcedures和Tables.

我知道如何针对EF进行定期检查/更新/获取/删除操作,但我找不到我的StoredProcedures.

这就是我所希望的:

using (Entities context = new Entities())
{
    context.MyStoreadProcedure(Parameters); 
}
Run Code Online (Sandbox Code Playgroud)

编辑1:

这是没有EF的情况:

sqlStr = "CALL updateGame(?,?,?,?,?,?,?)";

commandObj = new OdbcCommand(sqlStr, mainConnection);
commandObj.Parameters.Add("@id,", OdbcType.Int).Value = inGame.id;
commandObj.Parameters.Add("@name", OdbcType.VarChar, 255).Value = inGame.name;
commandObj.Parameters.Add("@description", OdbcType.Text).Value = ""; //inGame.description;
commandObj.Parameters.Add("@yearPublished", OdbcType.DateTime).Value = inGame.yearPublished;
commandObj.Parameters.Add("@minPlayers", OdbcType.Int).Value = inGame.minPlayers;
commandObj.Parameters.Add("@maxPlayers", OdbcType.Int).Value = inGame.maxPlayers;
commandObj.Parameters.Add("@playingTime", OdbcType.VarChar, 127).Value = inGame.playingTime;    

return Convert.ToInt32(executeScaler(commandObj));
Run Code Online (Sandbox Code Playgroud)

PS.如果需要,我可以更改EF版本

编辑1:

CREATE DEFINER=`106228`@`%` PROCEDURE `updateGame`(
    inId INT,
    inName VARCHAR(255),
    inDescription TEXT,
    inYearPublished DATETIME,
    inMinPlayers INT,
    inMaxPlayers INT,
    inPlayingTime VARCHAR(127)
)
Run Code Online (Sandbox Code Playgroud)

c# mysql stored-procedures entity-framework

35
推荐指数
4
解决办法
11万
查看次数

实体框架中的AsNoTracking()

我使用AsNoTracking()并知道在使用它时禁用了第一级缓存.但如何利用AsNoTracking()提高性能呢?使用它有什么好处?

entity-framework

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

创建具有特定大小的新文件

我需要创建包含随机数据但具有特定大小的文件.我无法找到一种有效的方法.

目前我正在尝试使用BinaryWriter将空char数组写入文件,但在尝试将数组创建为特定大小时,我得到Out of Memory Exception

char[] charArray = new char[oFileInfo.FileSize];

using (BinaryWriter b = new BinaryWriter(File.Open(strCombined, FileMode.Create), System.Text.Encoding.Unicode))
{
    b.Write(charArray);
}
Run Code Online (Sandbox Code Playgroud)

建议?

谢谢.

.net c#

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

在单个文件中RequireJS多个模块

我想将多个模块合并到一个文件中,但我找不到关于如何操作的官方文档.现在我使用下面的方法,它的工作原理,但我想知道以下内容:

  • 技术上是否正确?
  • RequireJS如何检查模块是否已加载?通过使用模块名称或文件名?
  • 在某些情况下,这个解决方案会多次启动模块吗?

的index.html

<script src="require.js"></script>
<script>
requirejs.config({
    paths: {
        'a': 'test',
        'b': 'test'
    }
});

require(['a', 'b'], function () {
    console.log('a & b loaded');
});
</script>
Run Code Online (Sandbox Code Playgroud)

test.js

console.log('loading test.js');
// I have some init here, like "Avoid `console` errors in IE"

define('a', function () {
    console.log('a module');
});

define('b', function () {
    console.log('b module');
});
Run Code Online (Sandbox Code Playgroud)

javascript requirejs

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

禁用与状态相关的整个表单元素.应对

我正在使用isFetchingprop 来禁用输入,但这会变得有用,因为我必须在每个输入字段中保留它.有没有办法禁用整个表单?像标签中的disable属性<form>或什么?

<form>
  <input type="text" disabled={this.props.isFetching} />
  <input type="text" disabled={this.props.isFetching} />
</form>
Run Code Online (Sandbox Code Playgroud)

html javascript forms reactjs

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

Angular 2未使用的标签错误

我正在尝试遵循Angular 2网站上的官方教程.本教程

我在atom IDE中遇到以下错误:

未使用的label.at第8行第1列

无法分配给'Hero',因为它不是variable.at第8行col 7

以下是我的代码:

import { Component } from '@angular/core';

export class Hero {
    id: number;
    name: string;
}

hero: Hero = {
  id: 1,
  name: 'Windstorm'
};

@Component({
    selector: 'my-app',
    template: `<h1>{{title}}</h1>
      <h2>{{hero.name}} details!</h2>`
})

export class AppComponent {
    title = 'Tour of Heroes';
    hero = 'Windstorm';
}
Run Code Online (Sandbox Code Playgroud)

结果如下:

屏幕截图

我做错了什么?感谢帮助.

typescript angular

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

实体框架核心级联删除一对多关系

public class Station : IEntitie
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public virtual ICollection<RegulatorySchedule> RegulatoryScheduleDispatchStations { get; set; }    

    public virtual ICollection<RegulatorySchedule> RegulatoryScheduleDestinationStations { get; set; }   
}

public class RegulatorySchedule : IEntitie
{
    [Key]
    public int Id { get; set; }

    public virtual Station DispatchStation { get; set; }      

    public virtual Station DestinationStation { get; set; }     
}


protected override void OnModelCreating(ModelBuilder modelBuilder)
{
        modelBuilder.Entity<RegulatorySchedule>()
            .HasOne(s => s.DestinationStation)
            .WithMany(s => s.RegulatoryScheduleDestinationStations)
            .OnDelete(Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Restrict);

        modelBuilder.Entity<RegulatorySchedule>()
            .HasOne(s => …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework entity-framework-core

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

SignalR如何保留从服务器到客户端的消息顺序

我有一个问题,当我从服务器向客户端发送消息时,他们没有按原始顺序到达客户端.我在这里有一个测试功能:

public async Task Hello(string group)
    {
        await Groups.Add(Context.ConnectionId, group);
        await Clients.Group("grp1").Hello("grp1");
        await Clients.Group("grp2").Hello("grp2");
        await Clients.All.Hello("all");
    }
Run Code Online (Sandbox Code Playgroud)

在客户端:

var chanceHub = $.connection.chanceHub;
chanceHub.client.Hello = function (message) {
    alert(message);
}
$.connection.hub.start().done(function () {
    chanceHub.server.hello("grp1");
});
Run Code Online (Sandbox Code Playgroud)

我希望按此顺序获得2个警报:"grp1"然后"all"但我总是首先得到消息"all".有什么方法可以解决这个问题吗?

c# model-view-controller signalr

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