小编Red*_*ett的帖子

Sublime Text换行和提交消息

我使用Sublime Text(3)作为我的默认Git提交消息编辑器.我尝试使用每行字符数的硬限制来遵循Git约定(第一行为50,其余为72).我目前在这些间隔设置了用于视觉参考的指南,但是不是手动必须在72个字符的末尾添加一行返回,我希望让ST自动为我插入一行返回.本质上,我希望能够在没有行返回的情况下进行编写,但是为了包装而放置了实际的返回,而不是仅仅在编辑器中进行可视化包装.有合理的方法吗?

commit-message commit word-wrap sublimetext sublimetext3

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

将铁-ajax数据绑定到模板

我有一个Polymer(1.0)应用程序,它加载了一个books来自AJAX 的列表:

book-service/book-service.html:

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">

<dom-module id="book-service">
    <style>

    </style>

    <template>
        <iron-ajax
          auto
          url="https://example.com/books.json"
          handle-as="json"
          on-response="booksLoaded"></iron-ajax>
    </template>

    <script>
    Polymer({
        is: 'book-service',

        properties: {
            books: { type: Array }
        },

        created: function(){
            this.books = [];
        },

        booksLoaded: function(request){
            this.books = request.detail.response
        }
    });
    </script>
</dom-module>
Run Code Online (Sandbox Code Playgroud)

components/book-list.html:

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../book-service/book-service.html">

<dom-module id="book-list">
    <style>

    </style>

    <template>
        <book-service id="service" books="{{books}}"></book-service>

        <div>
            <div>Books:</div>
            <ul>
            <template is="dom-repeat" items="{{books}}">
                <li>{{item.title}}</li>
            </template>
            </ul>
        </div>
    </template>

    <script>
    Polymer({is: 'book-list'}); …
Run Code Online (Sandbox Code Playgroud)

data-binding ajax polymer

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

按自定义属性选择铁页面

我有一个<iron-pages>带有几个孩子的元素,每个孩子都有<section>一些文本内容.默认情况下,我可以更改元素的selected属性,<iron-pages>显示的子项<section>将相应更改.

我想在子节点上使用自定义属性来选择它们:data-page.我将关联attrForSelected="data-page"属性添加到具有不同字符串(例如)的每个子节点<iron-pages>data-page属性home.但是,使用此系统,子项永远不会显示.即使data-page="home"具有属性的子项也不会在<iron-pages> selected属性设置为时显示home.

我选择自定义属性的错误是什么?

web-component polymer

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

运行具有意图的Android活动

我有一个活动,需要在活动开始时将参数作为intent extra传递.有没有什么方法可以从运行配置中设置一个演示参数,以允许我从Android Studio运行活动而不创建启动我正在进行的活动的临时默认活动?

android run-configuration android-intent android-activity

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

从内容脚本向页面 Javascript 发送消息

我在 Javascript 运行时中有一个选项卡的方法,我想从扩展的内容脚本中触发该选项卡。从表面上看,这需要在上下文之间传递消息,但我找不到 CS 到选项卡消息的任何文档,只有选项卡到 CS 或 CS 到后台。本质上,我想翻转内容脚本参考的“与嵌入页面的通信”部分。

到目前为止,我window通过注入一个小的 Javascript 有效负载将事件侦听器附加到选项卡(这将在正确类型的消息上触发选项卡方法):

listenerScript = document.createElement('script');
listenerScript.textContent = "window.addEventListener('message',function(ev){console.log('New event: ' + ev);},false);console.log('installed');";
(document.head||document.documentElement).appendChild(listenerScript);
listenerScript.remove();
Run Code Online (Sandbox Code Playgroud)

该侦听器已注册,但我无法弄清楚如何从我的内容脚本触发它。window.postMessage()内容脚本中的似乎没有做任何事情,并且文档仅讨论使用chrome.runtime创建端口,这是用于后台脚本的。

如何以最简单的方式将消息从内容脚本传递到选项卡?

javascript google-chrome-extension dom-events content-script

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

从Rails到Angularjs的JSON

我正在尝试使用Angularjs从我放在Heroku上的Rails测试应用程序中获取JSON.您将在下面找到我的Angular和Rails代码.

这是我在Firebug控制台中遇到的错误."NetworkError:404 Not Found - http://desolate-earth-2852.herokuapp.com/declarations.json "

这有什么原因不起作用吗?

Angularjs代码

var App = angular.module('App', []);

App.controller('TodoCtrl', function($scope, $http) {
  $http.get('http://desolate-earth-2852.herokuapp.com/declarations.json')
       .then(function(res){
          $scope.todos = res.data;        
        });
});
Run Code Online (Sandbox Code Playgroud)

Rails代码

  def index
    @declarations = Declaration.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @declarations }
    end
  end
Run Code Online (Sandbox Code Playgroud)

这是路线

Test::Application.routes.draw do
  root :to => 'welcome#index'
  get "welcome/index"
  resources :declarations
end
Run Code Online (Sandbox Code Playgroud)

javascript json ruby-on-rails heroku angularjs

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

方法:使用默认值循环参数

我正在构建一个 Ruby 对象,该对象在其initialize方法中具有默认参数:

attr_accessor :one, :two, :three

def initialize(one: nil, two: nil, three: nil)
  @one = one
  @two = two
  @three = three
end
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,这不是很 DRY,尤其是随着可初始化变量的数量增加。最终,我希望能够遍历每个参数并分配一个实例变量(splat 运算符和instance_variable_set

ruby constructor instance-variables splat

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