小编L.T*_*L.T的帖子

如何在xAxis上格式化时间使用d3.js

根据http://bl.ocks.org/mbostock/3883245上的演示

我不知道xAxis上的格式化时间

这是我的代码:js:


    var data = [{
            "creat_time": "2013-03-12 15:09:04",
            "record_status": "ok",
            "roundTripTime": "16"
        }, {
            "creat_time": "2013-03-12 14:59:06",
            "record_status": "ok",
            "roundTripTime": "0"
        }, {
            "creat_time": "2013-03-12 14:49:04",
            "record_status": "ok",
            "roundTripTime": "297"
        }, {
            "creat_time": "2013-03-12 14:39:06",
            "record_status": "ok",
            "roundTripTime": "31"
        },{
            "creat_time": "2013-03-12 14:29:03",
            "record_status": "ok",
            "roundTripTime": "0"
    }];
    var margin = {top: 20, right: 20, bottom: 30, left: 50};
    var width = 960 - margin.left - margin.right;
    var height = 500 - margin.top - margin.bottom;
    var …

javascript d3.js

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

该场景调用fs.close是必要的

我在nodejs API中找不到关于fs.close解释的更多信息.我想知道场景调用fs.close是必要的.例如:

var fs =  require('fs');
fs.writeFile("/home/a.tex","abc"); or like fs.appendFile("/home/a.tex","close")
fs.close(); //is it necessary?

如果我不打电话给fs.close有什么影响吗?

任何帮助表示赞赏.

file-io node.js

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

创建用户后如何防止自动登录

我在中添加了帐户密码和帐户基础包 Meteor

当我创建这样的用户时:

Accounts.createUser({username: username, password : password}, function(err){
          if (err) {
            // Inform the user that account creation failed
            console.log("Register Fail!") 
            console.log(err)
          } else {
               console.log("Register Success!")
            // Account has been created and the user has logged
          }    
  });
Run Code Online (Sandbox Code Playgroud)

帐户已创建且用户已登录.

例如,我以管理员身份登录,我想为某人创建一个帐户,但我不想在创建帐户后注销.

创建用户后如何防止自动登录?

我找到了accouts-password包的源代码:

48-63行:

// Attempt to log in as a new user.
Accounts.createUser = function (options, callback) {
  options = _.clone(options); // we'll be modifying options

  if (!options.password)
    throw new Error("Must set options.password");
  var verifier = …
Run Code Online (Sandbox Code Playgroud)

javascript meteor meteorite

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

如何定义全局模板助手功能?

在许多模板中,我想使用相同的功能,但必须在每个模板中定义它们.像这样:

function getNodesById(id){
    return collection.find({sid:id}).fetch();
}

Template.navigation.getNodesById= function(id){
    return getNodesById(id);
}

Template.body.getNodesById= function(id){
    return getNodesById(id);
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<Template name="navigation">
... 
{{#each getNodesById '1'}}
...
{{/each}}
...
</Template>
<Template name="body">
...
{{#each getNodesById '1'}}
...
{{/each}}
...
</Template>
...
<Template name="...">
 .....
</Template>
Run Code Online (Sandbox Code Playgroud)

有没有办法可以定义全局模板功能而不是模板?就像它:在javascript中:

    defined global tempele.functionA = function(...){
         return ...
    }

在HTML中:

<Template name ="a">
   {{#each  functionA ...}}
   {{/each }}
</Template>

<Template name ="b">
   {{#each  functionA ...}}
   {{/each }}
</Template>
<Template name="...">
    {{ #..  functionA ...}}
        ....
     {{/...}}
</Template > …
Run Code Online (Sandbox Code Playgroud)

javascript meteor spacebars meteor-helper

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

如何使用递归模板?

我不知道如何处理模板中的递归数组.我在handlebarsjs的文档中找不到任何内容

有我的代码:js:


    var branch = [{
                name:"firstLayerNodeA",
                has_branch:true,
                branch:[{
                        name:"secondLayoutNodeA",
                        has_branch:false
                    },{
                        name:"secondLayoutNodeB",
                        has_branch:true,
                        branch:[{
                                name:"thirdLayerNodeA",
                                has_branch:true,
                                branch:[{
                                        //fourth Layer
                                        //fifth Layer
                                        //.....
                                }]
                        }]
                }]
            },{
                name:"firstLayerNodeB",
                has_branch:false
            }]

HTML

<Template name="tree">
  <ul>
  {{#each brach}}
      <li>
        name
        {{#if has_branch}}
          <ul>
          {{#each brach}}
              <li>
                name
                {{#if has_brach}}
                      {{#each brach}}
                          .....third layer
                          .....fourth layer
                          ....
                      {{/each}}
                {{/if}}
              </li>
          {{/each}
          </ul>
        {{/if}}
      </li>
  {{/each}}
  </ul>
</Template>
Run Code Online (Sandbox Code Playgroud)

有很好的想法可以处理模板中的分支吗?任何帮助表示赞赏.

meteor

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

绘制线使用相同的y值,绘制底部的线条

我有同样的问题,

在yAxis中使用相同的值时,图表在底部排列

这是我的代码:


    var data = [{
            "creat_time" : "2013-03-19 10:28:30",
            "roundTripTime" : "32"
        }, {
            "creat_time" : "2013-03-19 09:07:12",
            "roundTripTime" : "45"
        }, {
            "creat_time" : "2013-03-19 08:57:09",
            "roundTripTime" : "26"
        }, {
            "creat_time" : "2013-03-19 08:47:10",
            "roundTripTime" : "90"
        }, {
            "creat_time" : "2013-03-19 08:37:12",
            "roundTripTime" : "80"
        }, {
            "creat_time" : "2013-03-19 08:27:08",
            "roundTripTime" : "36"
        }
    ]
    var data1 = [{
            "creat_time" : "2013-03-19 10:28:30",
            "roundTripTime" : "100"
        }, {
            "creat_time" : "2013-03-19 09:07:12",
            "roundTripTime" …

javascript d3.js

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

如何在发布中将数组转换为游标?

以下代码:

Meteor.push("svse",function(){   
   if(UserUtils.isAdmin(this.userId)) //is Administrator?
       return Svse.find();
   var arr = ["1","1.2"]; //just a example
   var nodes = Svse.find({sid:{$in:arr}}).fetch();
   var newNodes = new Array();
   for(i in nodes){
       var newNode = nodes[i];
       newNode["son"] = ArrayUtils.intersect(arr,newNode["son"]);
       newNodes.push(newNode)
    }
    return newNodes;
});

ArrayUtils={};
Object.defineProperty(ArrayUtils,"intersect",{
value : function(a,b){
    var ai=0;
    var bi=0;
    var result = new Array();
    while( ai < a.length && bi < b.length ){
        if(a[ai] < b[bi] ) {
            ai++;
        } else if(a[ai] > b[bi] ){
            bi++; 
        } else {
            result.push(a[ai]);
            ai++;
            bi++; …
Run Code Online (Sandbox Code Playgroud)

meteor

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

即使使用this.unblock(),流星方法也会阻塞.我是否在并发光纤中达到了极限?

这是我的代码:server.js

var fs = Npm.require('fs');
Meteor.methods({
    "test":function(a){
      this.unblock();
      if(a==1){
         //NVIDIA is a test file and size is 40 M ,
         //Make the call spend more time to watch block happen
          var data = fs.readFileSync("/home/ec/download/NVIDIA");
          for(var i=0;i<5;i++){
            fs.writeFileSync("/home/ec/download/test/NVIDIA"+i, data);
          }
      }
      console.log(a);   
      return a;
    }
});
Run Code Online (Sandbox Code Playgroud)

client.js

Meteor.call("test",1);
Meteor.call("test",2);

结果是:

1
2

第二个呼叫被阻止,并且未创建新的Fibers.对此有何想法?谢谢!

meteor

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

使用setTimeout查询Meteor中的Collection

我在model.js中定义了一个像这样的集合:

People = new Meteor.Collection("people");
Run Code Online (Sandbox Code Playgroud)

这是main.js中的代码:

function test2(){
  console.log(JSON.stringify(People.find().fetch()));
  setTimeout(test2,5000)
}
if (Meteor.isServer) {
  if(People.find().fetch().length === 0){
    var tom = {name:"Tom",age:18};
    People.insert(tom);
  }

  Meteor.startup(function () {
    test2();
  });
}
Run Code Online (Sandbox Code Playgroud)

以下是我得到的错误:

在此输入图像描述

我希望Meteor以设定的间隔自动在Collection上执行一些CRUD.所以我正在使用setTimeOut,但似乎很难.

关于我做错了什么的任何想法?

settimeout meteor

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