小编jcu*_*bic的帖子

如何在PHP中将数组转换为对象?

我怎样才能将这样的数组转换为对象?

    [128] => Array
        (
            [status] => Figure A.
 Facebook's horizontal scrollbars showing up on a 1024x768 screen resolution.
        )

    [129] => Array
        (
            [status] => The other day at work, I had some spare time
        )

)

php arrays casting object

329
推荐指数
21
解决办法
63万
查看次数

如何在Clojure中为函数参数创建默认值

我来这个:

(defn string->integer [str & [base]]
  (Integer/parseInt str (if (nil? base) 10 base)))

(string->integer "10")
(string->integer "FF" 16)

但它必须是一个更好的方法来做到这一点.

function clojure default-value optional-parameters

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

repo克隆时清空Git子模块文件夹

我在https://github.com/aikiframework/json上有一个回购.在我的本地副本上,我使用该命令添加了一个子模块

git submodule add git@github.com:jcubic/json-rpc.git json-rpc
Run Code Online (Sandbox Code Playgroud)

然后我做了一个提交和推送,更改出现在GitHub上(我可以点击它).但是当我克隆回购时

git clone https://github.com/aikiframework/json.git
Run Code Online (Sandbox Code Playgroud)

子模块文件夹json-rpc为空.

我在这里错过了什么?我忘记了什么吗?为什么那个文件夹是空的?

git version-control git-clone git-submodules

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

Angularjs过滤器不为空

尝试过滤掉具有非空属性的项目因此:

var details = [{name:'Bill', shortDescription: null}, {name:'Sally', shortDescription: 'A girl'}]
Run Code Online (Sandbox Code Playgroud)

我想只展示一个李; 莎莉的那一个.这是我试过没有成功的

<ul>
<li ng-repeat="detail in details | filter:{shortDescription:'!'}">
<p>{{detail.shortDescription}}</p>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

知道如何在不创建自定义过滤器的情况下做到这一点吗?或者即便如此,自定义过滤器会是什么样子?

javascript angularjs angularjs-filter

69
推荐指数
3
解决办法
6万
查看次数

如何卸载npm包?

我已经安装了grunt使用grunt,我无法将其删除.

我试过了:

$ sudo npm uninstall grunt
Run Code Online (Sandbox Code Playgroud)

但它给了警告:

npm WARN uninstall not installed in /home/kuba/projects/node_modules: "grunt-cli"
Run Code Online (Sandbox Code Playgroud)

我也试过rm,删除和取消链接.和sudo npm install grunt选项,它给:

npm WARN uninstall not installed in /usr/lib/node_modules: "grunt"
Run Code Online (Sandbox Code Playgroud)

但我仍然可以WARN从命令行调用.

编辑:

$ whereis grunt
grunt: /usr/local/bin/grunt
$ file /usr/local/bin/grunt
/usr/local/bin/grunt: symbolic link to `../lib/node_modules/grunt/bin/grunt'
$ ls /usr/local/lib/node_modules
grunt jshint
$ ls /usr/lib/node_modules
bower  csslint  devtools-terminal  npm  plato
Run Code Online (Sandbox Code Playgroud)

为什么我有2个目录与npm?删除它是否安全?

uninstall npm gruntjs

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

如何测试函数是否未被调用?

我正在测试路由器并且有两个功能,我需要测试第一个函数是否被调用而第二个函数没有被调用.有方法,toHaveBeenCalled但没有方法来测试函数是否被调用.我怎么测试呢?

我有这样的代码:

var args, controller, router;
beforeEach(function() {
    controller = {
        foo: function(name, id) {
            args = [].slice.call(arguments);
        },
        bar: function(name) {
        }
    };
    spyOn(controller, "foo").and.callThrough();
    spyOn(controller, "bar").and.callThrough();
    router = new route();
    router.match('/foo/bar/{{id}}--{{name}}', controller.foo);
    router.match('/foo/baz/{{id}}--{{name}}', controller.bar);
    router.exec('/foo/bar/10--hello');
});
it('foo route shuld be called', function() {
    expect(controller.foo).toHaveBeenCalled();
});
it('bar route shoud not be called', function() {
    // how to test if bar was not called?
});
Run Code Online (Sandbox Code Playgroud)

javascript jasmine

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

AngularJS UI-Router:获取带参数的状态的绝对URL

我希望能够在不改变状态的情况下更改地址'URL,以防止重新渲染.从我的搜索,ui-router目前不提供这个,但从$location.pathanuglar做.

所以,当然,我想用来$state.get(stateName)获取状态的URL,这样我就不会手动输入URL.

我有两个问题:

  1. $state.get(stateName)仅返回相对路径.我怎样才能获得绝对路径?
  2. 它还返回状态的定义,参数未定义.如何获取带有参数的URL?

例如,如果我有一个名为user.home.viewwith 的状态user.home,我将我的状态定义为

'user': {
     abstract: true,
     url: '^/users/'
},
'user.home': {
     url: ''
},
'user.home.view': {
     url: ':id/'
}
Run Code Online (Sandbox Code Playgroud)

所以现在,$state.get(user.home.view).url回归:id/.我怎样才能获得完整的URL(即/users/5/)?

angularjs angular-ui-router

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

如何使用moment.js设置00:00:00

我想获得当前日期,但时间应该是 00:00:00.000

我试过这个:

var m = moment();
m.set({hour:0,minute:0,second:0,millisecond:0});
console.log(m.toISOString());
Run Code Online (Sandbox Code Playgroud)

但我有:2016-01-12T23:00:00.000Z为什么23而不是00?

javascript momentjs

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

scope:{}和scope:true指令内部有什么区别?

我找不到关于Angular.js的这些信息,我注意到在我工作的时候,这两个值的工作方式不同.有什么不同?

.directive('foo', function() {

  return {
    scope: true
  };
});

.directive('foo', function() {

  return {
    scope: {}
  };
});
Run Code Online (Sandbox Code Playgroud)

angularjs

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

jQuery是monad吗?

我在某处读到jQuery是monad,这个答案表明underscore.js库中的链函数不是monad(而是comonad).并且回答这个类似的,表明它是幺半群.

那么,jQuery是monad吗?

monads jquery functional-programming

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