小编xia*_*kai的帖子

在Immutable.js中获取嵌套值

根据这里的文档:https://facebook.github.io/immutable-js/docs/#/Map/getIn

我应该能够通过为keyPath参数提供一个数组来获得深层嵌套的值.这就是我所做的,但是我得到的undefined是返回值.

http://jsfiddle.net/srxv4mwu/

var obj = Immutable.Map({categories: {1: 'a', 2: 'b'}});
var output = obj.getIn(['categories', 1]);
alert(output);
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

javascript immutable.js

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

为jenkins图库插件指定文件路径

我想要https://wiki.jenkins-ci.org/display/JENKINS/Image+Gallery+Plugin工作.然而,每次尝试让它工作只是告诉我:

Creating image galleries.
Creating archived images gallery.
This build has no artifacts. 
Skipping image gallery in this build.
Run Code Online (Sandbox Code Playgroud)

文档很稀疏,提供了3种类型的图像库:

Archived images gallery,In folder comparative archived images galleryMultiple folder comparative archived images gallery

对我毫无意义.

我唯一能做出正面或反面的是论证:一个需要"包含模式",另一个需要"基础根目录".

根据插件,

您可以使用'module/dist/*/ .zip'之类的通配符.请参阅Ant文件集的includes属性以获取确切的格式.基目录是工作区.您只能归档工作区中的文件.

哪个链接到http://ant.apache.org/manual/Types/fileset.html

我正在存储截图/workspace/selenium/screenshots/a_screenshot.png,

但以下不起作用:

包括模式:

**/*.png
*.png
selenium/screenshots/*.png
Run Code Online (Sandbox Code Playgroud)

基根目录:

selenium/screenshots
/selenium/screenshots
/selenium/screenshots/*.png
/selenium/screenshots/*.png
Run Code Online (Sandbox Code Playgroud)

而且我已经没有想法了.有没有人以前成功使用过这个插件,怎么样?

jenkins jenkins-plugins

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

如何在angular的$ parse中赋值

我有一个字符串引用我的一个范围值,如下所示:

var reference_string = "form.name";
Run Code Online (Sandbox Code Playgroud)

我想为它引用的对象赋值:

$scope.form.name = 'newvalue';
Run Code Online (Sandbox Code Playgroud)

环顾四周,我找到了两种可能的解决方案:使用普通JS或使用angular $ parse函数.

但是,似乎$ parse函数只返回值.我可以这样做,以便我可以分配一个新值吗?

即.我想做点什么

var reference_string = "form.name";
var reference = getReference($scope, reference_string); // ideally using an angular in-built function like $parse
reference = 'newvalue'; // should have the same effect as $scope.form.name = 'newvalue';
Run Code Online (Sandbox Code Playgroud)

angularjs

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

nginx将所有内容重写为index.php,白名单除外

首先,我试图搜索类似的问题,但这些问题的解决方案是特定的代码行,我无法自定义以满足我的需求.

我有一个Codeigniter安装,我正在尝试从Apache迁移到nginx.然而,在Apache中,.htaccess非常简单:它需要白名单,并重写其他所有内容index.php.

RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|core|uploads|js|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)

但是在nginx中,我尝试了if和try_files指令,以及乱搞地点,但无济于事.我还不知道nginx如何读取服务器配置,而且在线教程有点令人困惑.

此外,index.php不会位于Web根目录中,而是位于子目录中server.

因此,我还需要确保甚至以/ server开头的URI请求都不会转到目录,而是转到 index.php

到目前为止,这是我的nginx虚拟主机配置:

server {
    listen 80;
    server_name example.com;

    root /home/example/public_html;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;


    location / {
        index index.htm index.html index.php;
    }

    location ~ \.php$ {
        fastcgi_pass        unix:/var/run/php-fpm/example.sock;
        include             fastcgi_params;
        fastcgi_param       PATH_INFO $fastcgi_script_name;
        fastcgi_param       SCRIPT_FILENAME $document_root$fastcgi_script_name;

    }

    location ~* ^.*(/|\..*) { 
        try_files $uri $uri/ /server/index.php;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
} …
Run Code Online (Sandbox Code Playgroud)

regex .htaccess rewrite codeigniter nginx

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

声明后执行命名函数

我知道这可以用于匿名函数

(function toBeExecutedImmediately() {
    // Code
}());
Run Code Online (Sandbox Code Playgroud)

我有一个我希望在其他地方使用的功能,但也应该立即执行.是否可以使用一个语句而不是以下语句来执行此操作?不需要返回值.

function toBeExecutedImmediately() {
    // Code
};

toBeExecutedImmediately();
Run Code Online (Sandbox Code Playgroud)

javascript

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

检查扩展类中是否存在方法,但父类是否存在

使用method_exists,它会检查所有方法,包括父类.

例:

class Toot {
    function Good() {}
}

class Tootsie extends Toot {
    function Bad() {}
}

function testMethodExists() {
    // true
    var_dump(method_exists('Toot', 'Good'));

    // false
    var_dump(method_exists('Toot', 'Bad'));

    // true
    var_dump(method_exists('Tootsie', 'Good'));

    // true
    var_dump(method_exists('Tootsie', 'Bad'));
}
Run Code Online (Sandbox Code Playgroud)

如何检查该方法仅存在于当前类而不是父类(即.Tootsie)?

php

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

从指令中访问其他元素的ng-model

我有一个指令,它应该更新另一个输入.

但是,我找不到从指令中访问其他输入的ng-model的方法

accessOther指令

angular.module('test', [])
.directive('accessOther', function() {
  return {
    require: '?ngModel',
    link: function(scope, elem, attr, ngModel) {
      // ngModel here only refers to the current input
      ngModel.$setViewValue('test');

      // how to get access/modify another input? (ie. #outside)
    }
  }
})
.controller('parentController', function() {
  var pc = this;
  pc.data = {};
})
.controller('nestedController', function() {
});
Run Code Online (Sandbox Code Playgroud)

在下面的代码中,accessOther指令位于#current但正在尝试更改#outside

<body ng-app="test" ng-controller="parentController as pc">
    <input type="text" ng-model="pc.data.parent" id="parent" placeholder="parent">

    <div ng-controller="nestedController as nc">
        <input type="text" ng-model="pc.data.outside" id="outside" placeholder="outside">
        <br>
        <input type="text" …
Run Code Online (Sandbox Code Playgroud)

angularjs

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

从super更新ruby哈希中的单个值

我在rspec中编写测试,并试图用一些变量来声明let.

describe 'my_test' do
    let(:params) {{
        :happy => 1,
        :sad => 0,
    }}

    context 'mixed' do
        let(:params) {{
            :happy => 1,
            :sad => 1,
        }}
    end
end
Run Code Online (Sandbox Code Playgroud)

但后来我看到变量如何被过度编写super,这对于很长的params列表很方便:http://myronmars.to/n/dev-blog/2013/02/rspec-2-13-is-released

所以我的问题是,如何覆盖原始哈希中的单个值?我尝试过搜索,但只能找到覆盖所有值的方法.有下面的内容吗?

let(:hash) { super().updatehash('sad', '1') }
Run Code Online (Sandbox Code Playgroud)

ruby rspec

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