小编Rya*_*ing的帖子

Graphcool/GraphQL创建关系变异

我有以下GraphQL架构.它BooksAuthors一个多对多的关系.如何为现有作者创建新的Book变异?


模式

type Author implements Node {
  books: [Book!]! @relation(name: "BookAuthors")
  createdAt: DateTime!
  id: ID! @isUnique
  name: String!
  updatedAt: DateTime!
}

type Book implements Node {
  authors: [Author!]! @relation(name: "BookAuthors")
  createdAt: DateTime!
  id: ID! @isUnique
  title: String!
  updatedAt: DateTime!
}
Run Code Online (Sandbox Code Playgroud)

突变

mutation CreateBook($title: String!, $authors: [Author!]) {
    createBook(
      title: $title,
      authors: $authors,
    ) {
      id
      title
    }
  }
Run Code Online (Sandbox Code Playgroud)

变量

{
  "title": "Ryans Book",
  "authors": ["cj5xti3kk0v080160yhwrbdw1"]
}
Run Code Online (Sandbox Code Playgroud)

graphql graphcool

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

Ruby扫描正则表达式

我正在尝试拆分字符串:

"[test| blah] \n [foo |bar bar bar]\n[test| abc |123 | 456 789]"
Run Code Online (Sandbox Code Playgroud)

进入以下数组:

[
  ["test","blah"]
  ["foo","bar bar bar"]
  ["test","abc","123","456 789"]
]
Run Code Online (Sandbox Code Playgroud)

我尝试了以下,但它不太正确:

"[test| blah] \n [foo |bar bar bar]\n[test| abc |123 | 456 789]"
.scan(/\[(.*?)\s*\|\s*(.*?)\]/)
# =>
# [
#   ["test", "blah"]
#   ["foo", "bar bar bar"]
#   ["test", "abc |123 | 456 789"]
# ]
Run Code Online (Sandbox Code Playgroud)

我需要在每个管道而不是第一个管道上拆分.实现这一目标的正确正则表达式是什么?

ruby regex

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

Rails从Helper模块返回多个content_tags

我写了以下帮助:

def section_to_html (block)
      case block[0].downcase
      when "paragraph"
        block.shift
        block.each do |value|
          return content_tag(:p, value)
        end
      end
  end
Run Code Online (Sandbox Code Playgroud)

它目前正在解析这些数组.

["paragraph", "This is the first paragraph."]
["paragraph", "This is the second.", "And here's an extra paragraph."]
Run Code Online (Sandbox Code Playgroud)

它返回:

<p>This is the first paragraph.</p>
<p>This is the second.</p>
Run Code Online (Sandbox Code Playgroud)

有没有办法累积content_tag?所以它返回:

<p>This is the first paragraph.</p>
<p>This is the second.</p>
<p>And here's an extra paragraph.</p>
Run Code Online (Sandbox Code Playgroud)

我现在唯一的解决方案是使用部分解决方案.但是,一旦我开始添加更多案例条件,这将变得非常混乱.

html ruby module ruby-on-rails helper

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

动画完成后调用函数

我有两个功能可以在我的页面上打开和关闭侧边栏.

function closeSidebar(functionAfterClose) {
        var functionAfterClose = functionAfterClose || function() {};
        $("#sidebar").removeClass("open");
        $("#sidebar").animate({marginLeft: margin*-1},"fast", "swing", functionAfterClose);
        $("#dummy-column").animate({marginLeft: margin*-1},"fast", "swing");
}

function openSidebar() {
        $("#sidebar").addClass("open");
        $("#sidebar").animate({marginLeft:0},"fast", "swing");
        $("#dummy-column").animate({marginLeft:0},"fast", "swing");
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试将close函数传递给closeSidebar()以在关闭动画完成后运行.但它似乎是直接运行而不是等待侧边栏动画完成.

closeSidebar(function() {
                alert("function called");
                $(this).addClass("current");
                openSidebar();
            });
Run Code Online (Sandbox Code Playgroud)

动画完成后,我错过了什么才能调用函数?

jsFiddle - 单击右侧的按钮,它应该动画,调用该函数,然后再次动画回来.

javascript jquery animation

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

自定义jQuery方法独立于元素的每个实例

我创建了一种方法,可以在鼠标悬停时在图像的一侧显示黑条.当它只有一个图像时,一切都很好,但是当应用于多个图像时,如果鼠标悬停,则两个图像上都会出现黑条.

是否可以让每个图像彼此独立地操作,以便鼠标悬停事件仅激活该特定图像的黑条?


jsFiddle - http://jsfiddle.net/7kw8z/11/


我通过这个方法调用 $("img.edit").panzoom();

这是方法:

!function($){


$.fn.panzoom = function() {
    var $this = $(this);
    this.imagesLoaded(function(){

        $this.wrap('<div class="img_wrapper" />');

        var imgEl = $this.parent(".img_wrapper");

        imgEl.width($this.width());
        imgEl.height($this.height());
        //imgEl.offset({top:$this.offset().top,left:$this.offset().left});

        imgEl.append('<div class="img_menu" />');
        menuEl = imgEl.children(".img_menu");


        imgEl.hover(function() {
            $(menuEl).css("visibility", "visible");
        },  function() {
            $(menuEl).css("visibility", "hidden");
        });

    });
}

}(window.jQuery);
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

从javascript中的嵌套对象获取最深层次的孩子

我有两种类型的 a 对象, agroup和 an item。一个组可以有childrenwhich 是 anarray of groups或 an array of items

我最终得到了一系列嵌套组(可以是无限级深),我需要检索所有项目,无论有多少级深,只有一个组可以使用。

有没有办法从以下数据结构中的顶级组中检索所有项目?

{
  type: 'group',
  children: [
    {
      type: 'group',
      children: [
        {
          type: 'group',
          children: [{type:'item'}, {type:'item'}, {type:'item'}]
        },
        {
          type: 'group',
          children: [{type:'item'}, {type:'item'}, {type:'item'}]
        },
        {
          type: 'group',
          children: [{type:'item'}, {type:'item'}, {type:'item'}]
        },
      ]
    },
    {
      type: 'group',
      children: [
        {
          type: 'group',
          children: [{type:'item'}]
        },
        {
          type: 'group',
          children: [{type:'item'}]
        },
        {
          type: 'group', …
Run Code Online (Sandbox Code Playgroud)

javascript nested

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

垂直对齐绝对定位

在下面的代码中,我试图使绿色div.middle元素中的元素垂直对齐到中间.


我尝试了表格单元格方法,但无法使其正常工作.我听说这是由于绝对定位并尝试了这个解决方案没有运气: CSS - 垂直对齐表格单元格无法使用绝对位置

这似乎是由于.table-cell没有高度 - 我希望它的高度等于其父容器,其高度不同.


的jsfiddle:

http://jsfiddle.net/q5jKM/1/


有没有人知道让绿色div.middle元素垂直对齐到中间的方法?任何方法都可以.它只需要能够处理其可变高度.只用css是否可能?或者我是否必须加入一些jQuery?


编辑:

box-align也不是一个可行的解决方案,因为浏览器支持并被新标准取代.


CSS

     html,body{height:100%;margin:0}
#sidebar {
    width: 22em;
    position:fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index:2;
    color: #ffffff;
    background-color: #333333;  
    overflow:auto;
    height: 100%;
}

#sidebar .nav {
    width: 3em;
    float: right;
    background-color: #2e2e2e;
    border-left: 2px groove #454545;
    height: 100%;
    position:relative;
    min-height:34em;    
}

#sidebar .content {
    height: 100%; 
    width: 16.875em; /*    17-(2/16)   - 20em - .nav - nav border*/
    float:left; 
    position:relative;
    min-height:34em;
}

#sidebar .top {
    position:absolute;
    top:0;
}
#sidebar …
Run Code Online (Sandbox Code Playgroud)

css vertical-alignment css-tables

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

Ruby .split()正则表达式

我正在尝试将字符串"[test| blah] [foo |bar][test|abc]"拆分为以下数组:

[
    ["test","blah"]
    ["foo","bar"]
    ["test","abc"]
]
Run Code Online (Sandbox Code Playgroud)

但我无法正确表达我的正则表达式.


红宝石:

@test = '[test| blah] [foo |bar][test|abc]'.split(%r{\s*\]\s*\[\s*})
@test.each_with_index do |test, i|
  @test[i] = test.split(%r{\s*\|\s*})
end
Run Code Online (Sandbox Code Playgroud)

我不在那里,这回来了:

[
    [ "[test" , "blah" ]
    [ "foo" , "bar" ]
    [ "test" , "abc]" ]
]
Run Code Online (Sandbox Code Playgroud)

实现这一目标的正确正则表达式是什么?如果我还可以考虑新线路,那会很棒,比如说:"[test| blah] \n [foo |bar]\n[test|abc]"

ruby regex string split ruby-on-rails

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

JavaScript - 将参数传递给匿名函数

我正在调用一个匿名函数:

        closeSidebar(function() {
            alert("function called");
            $(this).addClass("current");
            setTimeout(function(){openSidebar()}, 300);
        });
Run Code Online (Sandbox Code Playgroud)

但是$(this)没有按预期工作,我需要将它作为参数传递给函数.经过一番研究后,我认为这样可行:

            closeSidebar(function(el) {
               $(el).addClass("current");
               setTimeout(function(){openSidebar()}, 300);
            })(this);
Run Code Online (Sandbox Code Playgroud)

但事实并非如此.如何为匿名函数添加参数?

jsFiddle - 单击右侧的按钮,它会动画然后调用上面的函数.当按钮具有"当前"类时,按钮左侧将有一个白色条,但类永远不会改变.

javascript jquery

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

来自 Javascript 的 Svelte Mount DOM 元素

我正在尝试使用pixi.jsSvelte 安装画布,如下所示。app.view是一个HTML Canvas元素,但我不知道如何用 Svelte 显示它。

<script>
    import * as PIXI from 'pixi.js'
    import { onMount } from 'svelte';
    let app = new PIXI.Application({ 
        width: 256,         // default: 800
        height: 256,        // default: 600
        antialias: true,    // default: false
        transparent: false, // default: false
        resolution: 1       // default: 1
    })
</script>

<style></style>

<app.view />
Run Code Online (Sandbox Code Playgroud)

我暂时只是使用它,但如果能够将其添加到模板中那就太好了。

    onMount(() => {
        document.body.appendChild(app.view);
    })
Run Code Online (Sandbox Code Playgroud)

svelte

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

403 & 500 error on Apache server when using .htaccess

I'm trying to use a .htaccess file on the Apache Server running on my Macbook (OS X Lion). I've used the following guide to modify the permissions in my Apache configuration file allow use of .htaccess: http://clagnut.com/blog/350/ - Substituting in the OS X Lion's new httpd.conf file locations.

However, when adding a .htaccess file I get a 500 Internal Server Error.

With the User.conf set adjusted to the following, I get a 403 Forbidden Error.

AllowOverride All #AuthConfig gives 500 …
Run Code Online (Sandbox Code Playgroud)

apache .htaccess mod-rewrite httpd.conf osx-lion

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

Rails数组条件查询

我已经写了下面的方法来结合ReferencesSections模式,它的孩子:

def combined_references
    ids = []
    ids << self.id
    self.children.each do |child|
      ids << child.id
    end
    Reference.where("section_id = ?", ids)
  end
Run Code Online (Sandbox Code Playgroud)

但是section.combined_references返回以下错误:

Mysql2::Error: Operand should contain 1 column(s): SELECT `references`.* FROM `references`  WHERE (section_id = 3,4)
Run Code Online (Sandbox Code Playgroud)

它似乎收集了id的正确值,我是否错误地构造了查询?

ruby-on-rails

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