小编rep*_*rat的帖子

如何加速d3.js中的力布局动画

我使用D3.js渲染大约500个节点和它们之间的链接.通常需要10秒才能使布局稳定下来(迭代收敛).

如何加速整个过程,比如节点在动画过程中移动速度提高了2倍.然后时间将是50%(用于迭代的CPU时间应远小于10秒,但我如何减少动画时间).

我试过了:

  1. 手动管理for循环中的tick()一定时间,比如100次,它更快,但动画将隐藏在用户之外,这是一个很大的损失.
  2. 增加链接强度将有所帮助,节点在动画期间将移动得更快.但布局非常敏感,任何小的拖动都可能导致许多节点移动.

有什么建议?谢谢.

javascript d3.js

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

AngularJs-ng-options在ajax调用后没有绑定

我尝试在ajax调用后更改所选的ng-options索引,但不会更改.

//Html Section...

<select id="fooId" ng-model ="foo.formula"
   ng-options="formulas as name for (formulas, name) in the_formula"></select>

//End Html Section...


//js file...

//get list of formula from server...
TheSource.Get.then(function(response){
    $scope.the_formula = response.the_formula;
});


//do something awesome, then..
//binding data from server...

TheData.Get.then(function(response){
    //binding the data to view...
    //all of the element is binding, except the ng-options part..
    $scope.foo = response; 

    //not working..
    //$scope.formula = response.formulaId //it is return integer ID like (1, 2, 3, etc..)
});

// End js file...
Run Code Online (Sandbox Code Playgroud)

这是My API发送的数据. …

javascript ajax jquery angularjs ng-options

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

使用箭头键盘而不是鼠标时,ng-options模型未更新

我创造了js小提琴:小提琴

我创建了一个包含一些ng-options的表单,当你使用按钮而不是鼠标时它会有奇怪的行为(只需单击文本框并按"tab",你就可以使用箭头键选择它).

<form ng-controller="MyApp" id="Apps" name="Apps" ng-submit="SendApp()" role="form" novalidate>
    <input type="text" name="title" ng-model="Info.Title" />
    <select id="Formula" ng-model ="Info.Genre" ng-change= "ChangeGenre()"
                        ng-options="id as name for (id, name) in Genre" blank></select>
     <select class="form-control" ng-model ="Info.Program" 
                        ng-options="Program as Name for (Program, Name) in Program" ng-change="ChangeProgram()" blank></select>
    <h3>{{Info.Genre}}</h3>
    <h3>{{Info.Program}}</h3>
    <button type=submit>Submit this </button>
</form>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

var theApp = angular.module("TheApp", []);

theApp.controller("MyApp", ['$scope', function($scope){
    $scope.Program = {"1":"Music","2":"Theater","3":"Comedy"};

    $scope.Genre = {"1":"Mystery", "2":"Thriller", "3":"Romance"};

    $scope.ChangeProgram = function(){
        alert($scope.Info.Program + " " + $scope.Info.Genre);
    }
    $scope.ChangeGenre = …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery angularjs ng-options

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

使用restsharp反序列化JSON

我试图从Harvest反序列化数据,但它失败了(没有错误):https://github.com/harvesthq/api#api-json

返回的数据如下所示:

更新 (请参阅底部的完整JSON响应)

我运行下面代码时的输出是一个带有x个帖子的列表,其中每个帖子包含一个id = 0

是否有一个设置或我错过的东西让它忽略/解析周围的[]?

[DeserializeAs(Name = "project")]
public class Project
{
    public int id { get; set; }

    //public string name { get; set; }

    //[DeserializeAs(Name = "created-at")]
    //public DateTime CreatedAt { get; set; }           
}

// The following is the methods to request for testing

public List<Project> GetProjects()
{
    var request = new RestRequest("projects", Method.GET);
    request.RequestFormat = DataFormat.Json;
    return Execute<List<Project>>(request);
}

private T Execute<T>(RestRequest request) where T : new()
{
    var client …
Run Code Online (Sandbox Code Playgroud)

c# json restsharp deserialization

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

在ServiceStack服务上进行身份验证后访问客户端上的AuthSession

我对会话文档有点困惑,所以让我说我已经从客户端发送身份验证数据并检索ss-id和ss-pid,如下所示:

var client = new JsonServiceClient("http://somewhere/theAPI/");
var response = client.Post(new Auth() {UserName = "myuser", Password = "password123"});
var myCookie= client.CookieContainer.GetCookies(new Uri("http://somewhere/theAPI"));
Run Code Online (Sandbox Code Playgroud)

我如何从服务栈中检索姓氏,电子邮件等的AuthSession信息?我需要它存储在其他地方,如在memcache服务器,并从中检索?

或者我需要在客户端构建我的身份验证?并只是使用API​​来检索数据?

authentication asp.net-mvc servicestack

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

无法获取Integration类ninject的默认构造函数

我是使用ninject和Dependency Injection的新手,并且在使用它时遇到了问题.

我尝试在我的类库中使用Ninject,并构建集成测试.现在,我在很多例子中看到,使用ninject只是指定了DI模块,如下所示:

Public Class DIModule : NinjectModule
public override void Load()
{
        Bind<IUSAServices>().To<USAServices>();
} 
Run Code Online (Sandbox Code Playgroud)

然后在我的测试类中,我尝试调用我的依赖是这样的:

[TestClass]
public class USAIntegrationTests
{

    private readonly IUSAServices _usaService;

    public USAIntegrationTests(IUSAServices usaServices)
    {
        _usaService = usaServices;
    }

    [TestMethod]
    public void ValidateUserTests()
    {
        Assert.IsTrue(_usaService.ValidateUser("username1", "password1"));
    }
}
Run Code Online (Sandbox Code Playgroud)

并得到此错误:

Unable to get default constructor for class USATests.IntegrationTests.USAIntegrationTests.
Run Code Online (Sandbox Code Playgroud)

但是,我阅读文档并尝试这样:

[TestClass]
public class USAIntegrationTests
{

    private readonly IUSAServices _usaService;

    public USAIntegrationTests()
    {
        using (IKernel kernel = new StandardKernel(new DIModule()))
        {
            _usaService = kernel.Get<IUSAServices>();
        }
    }

    [TestMethod]
    public void …
Run Code Online (Sandbox Code Playgroud)

design-patterns dependency-injection ninject c#-4.0

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

C#使用Return void和object重叠(string)

我尝试创建一个重载函数,返回void或字符串,如下所示:

public string Message { get; private set; }

public void Foo (Bar bar)
{
    Message = "Hello World!";
}

public string Foo (Bar bar)
{
    return "Hello World!";
}
Run Code Online (Sandbox Code Playgroud)

但我得Compile Time错误说:

 Type 'Foo' already defines a member called with the same   parameter types.
Run Code Online (Sandbox Code Playgroud)

有什么方法可以实现那种过载吗?

c# overloading

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

log4net的文件和数据库多重配置

我有Web API需要将日志数据写入文件和数据库.是否可以配置这样的设置?我想了解ILoggerRepository,但我很困惑.有人可以给我一些关于如何配置它以及如何在应用程序中使用它的提示吗?

c# log4net

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