小编Pan*_*agi的帖子

如何扩展Ember的对象?

我正在寻找一种方法来扩展Ember的Object以包含一些额外的方法,以便它们在我的应用程序中的每个对象(View,ArrayController等)都可用.

具体来说,我想定义一些方法,介绍控制器,模型,视图,模板,帮助器等的一些命名约定.

例如:

如果查看的类名ArticlesListView,然后它的相关模型Article,控制器动作被命名为listArticlesController,模板是在app/articles一个名为list.js.hjs...

例如,最终结果应该是App.ArticlesListView.model()返回App.Article.

那么如何扩展核心Ember对象呢?

Ember.Object.extend({     // <--- ???

    model: function(context, params){

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

ember.js

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

从jQuery对象创建Ember View

我正在考虑将Ember与现有的Rails应用程序集成,以利用Ember的绑定,事件(didInsertElement等)......

现在我不想将我的erb视图转移到把手,而是想要创建Ember View对象并将它们附加到DOM中已有的各种元素.例如,我可能有

<html>
  <body>
    <div class="header">

    </div>

    <div class="content">

    </div>

    <div class="footer">

    </div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

和(在DOM准备好的情况下)为每个元素创建一个View:

App.HeaderView = Ember.View.create({
   // capture $('.header') to this
   // console.log(this.$().attr('class')) should then output `header`
});
Run Code Online (Sandbox Code Playgroud)

ember.js

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

如何在页面被加入书签时进行客户端检测?

是否可以使用Javascript检测页面何时在浏览器中添加书签?

javascript browser bookmarks client-side detect

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

如何告诉谷歌机器人某些链接不再存在

在网站的最初几天,我在生成一些链接时犯了一个错误; 跟随它们输出数据库错误.

谷歌机器人已尝试关注这些链接,现在它们在网站管理员工具中显示为抓取错误.虽然我已经纠正了错误,谷歌仍然试图抓取它们.

如何告诉Google这些链接不再存在,并且它们导致无处可去?我不能做一个301重定向原因,可以说链接是有效的,可以索引它们.

seo googlebot web-crawler

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

Rails 3没有这样的文件加载 - Nokogiri(LoadError)

我收到以下错误:

/srv/www/cyprus-weather.net/cyprus-weather/vendor/cache/ruby/1.9.1/gems/activesupport-

3.1.0/lib/active_support/dependencies.rb:306:in `rescue in depend_on': 

No such file to load -- Nokogiri (LoadError)
Run Code Online (Sandbox Code Playgroud)

仅在执行生产环境时(例如:) rails c production.在开发模式中,一切运行良好.

谁知道什么可能是错的?

ruby nokogiri ruby-on-rails-3

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

猴子补丁ActiveRecord的PostgreSQLAdapter方法

关于这个问题,我试图覆盖postgresql_version定义的方法ActiveRecord::ConnectionAdapters::PostgreSQLAdapter返回PostgreSQL版本:

module ActiveRecord
  module ConnectionAdapters
    class PostgreSQLAdapter < AbstractAdapter

      protected
        # Returns the version of the connected PostgreSQL server.
        def postgresql_version
          80200
        end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

但补丁未应用.我尝试在config/initializer中并在/ lib文件中要求它.救命?

activerecord monkeypatching ruby-on-rails ruby-on-rails-3

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

如何在JSON模式中扩展模式?

我正在使用JSON模式进行数据建模。我定义一个基Document模式,即我以后使用来定义模型模式(例如ProductCategoryUser等等)。

我这样做是因为我希望所有模型都继承某些结构/规则。例如每模型实例应当具有某些共同的性质(如,idcreatedAtupdatedAt)。在OOP术语中:Product extends Document因此,它继承其实例属性。在模式中,术语(我认为)Document是用于创建模型模式的元模式。

我已经定义了Document模式,如下所示:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "id": "http://example.com/schemas/document.json#",
  "title": "Document",
  "type": "object",
  "additionalProperties": false,
  "required": ["type", "name", "fields"],
  "properties": {
    "type": {
      "constant": "document"
    },
    "name": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "readOnly": {
      "type": "boolean"
    },
    "properties": {
      // common properties 
      // model-specific properties
    }
  }
}
Run Code Online (Sandbox Code Playgroud)
  1. 如何指定文档元模式“扩展”的基础架构JSON(草案-07),这样我就不必定义草案(所有属性$schemaid …

schema json jsonschema

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