我正在尝试为三角形设置动画(想想,角度规针),使其在给定点旋转(参见红点).
var svg = Raphael("container",400,400),
triangle = svg.path("M210 200L190 200L200 100Z").attr({fill:"#000"}),
circle = svg.circle(200,200,5).attr({fill:"#f00"});
// to animate ??
triangle.animate({rotation:100,cx:200,cy:200},1000,'<>');
// doesn't work
Run Code Online (Sandbox Code Playgroud)
我可以沿着那个中心旋转(没有动画):
// to rotate with center point 200,200, works fine
triangle.rotate(80,200,200);
Run Code Online (Sandbox Code Playgroud)
但我无法为我的生活弄清楚如何为旋转设置动画,使其围绕该点旋转.它总是似乎在路径的中心旋转.
有帮助吗?
我有一张地图,根据地图的gbounds显示位置点.例如,无论何时移动/缩放地图,我都会找到属于这些边界内的位置的边界和查询.不幸的是,当完全缩小时,我无法显示所有位置.原因是,gmaps将最小/最大长度报告为地图边缘的任何内容,但如果缩小到足够大,则可以获得排除可见位置的纵向范围.
例如,如果您缩放地图以便在最左侧和最右侧看到NorthAmerica两次.最小/最大长度约为:-36.5625至170.15625.但这几乎完全排除了位于-180到-60范围内的NorthAmerica.显然,这是麻烦,你可以清楚地看到大陆北美洲(两次),但是当我询问我在从谷歌地图的范围内的位置,不返回北美洲.
我找到min/max long的代码是:
bounds = gmap.getBounds();
min_lat = bounds.getSouthWest().lat()
max_lat = bounds.getNorthEast().lat()
Run Code Online (Sandbox Code Playgroud)
有没有人遇到这个,谁能建议一个解决方法?在我的头顶我只能做一个黑客攻击:检查缩放级别并在必要时将最小/最大拉特硬编码为-180/180,这绝对是不可接受的.
我正在编写一个带有以下标记的小部件:
<g:HTMLPanel ui:field="shortcutPanel" styleName="{style.shortcut}">
<g:Image ui:field="shortcutImage"></g:Image>
<span ui:field="shortcutLabel"></span>
</g:HTMLPanel>
Run Code Online (Sandbox Code Playgroud)
所以基本上是一个包装和图像和标签的div.现在,我不想在图像/跨度上添加事件处理程序,而是希望将onClick与HTMLPanel相关联.然而,我的问题是gwt告诉我
shortcutPanel没有关联的addClickHandler方法
所以我假设不同的是HTMLPanel没有实现HasClickHandlers
或沿着那条线.我想知道将点击处理程序附加到诸如HTMLPanel之类的Ui元素的标准方法是什么,甚至更好,是否有这样的GWT Widget本质上是一个div包装器,我可以轻松地将事件附加到@UiHandler注解.
我有一些ARes模型(见下文),我正在尝试使用关联(这似乎完全没有文档,也许不可能,但我想我会尝试一下)
所以在我的服务方面,我的ActiveRecord对象将呈现类似的东西
render :xml => @group.to_xml(:include => :customers)
Run Code Online (Sandbox Code Playgroud)
(参见下面生成的xml)
模型组和客户是HABTM
在我的ARes方面,我希望它可以看到<customers>
xml属性并自动填充该.customers
Group对象的属性,但是不支持has_many等方法(至少据我所知)
所以我想知道ARes如何反映XML来设置对象的属性.例如,在AR中,我可以def customers=(customer_array)
自己创建并设置它,但这似乎在ARes中不起作用.
我找到一个"关联"的建议就是有一个方法
def customers
Customer.find(:all, :conditions => {:group_id => self.id})
end
Run Code Online (Sandbox Code Playgroud)
但这有一个缺点,就是它会进行第二次服务电话来查找这些客户......并不酷
我希望我的ActiveResource模型能够看到XML中的客户属性并自动填充我的模型.有人对此有经验吗??
# My Services
class Customer < ActiveRecord::Base
has_and_belongs_to_many :groups
end
class Group < ActiveRecord::Base
has_and_belongs_to_many :customer
end
# My ActiveResource accessors
class Customer < ActiveResource::Base; end
class Group < ActiveResource::Base; end
# XML from /groups/:id?customers=true
<group>
<domain>some.domain.com</domain>
<id type="integer">266</id>
<name>Some Name</name>
<customers type="array">
<customer>
<active type="boolean">true</active>
<id type="integer">1</id>
<name>Some …
Run Code Online (Sandbox Code Playgroud) 我刚刚在我的程序中发现了一些数字操作的错误,而且我得到了一个 FloatDomainError (NaN)
所以我开始记录传入的号码:
if(metric.is_a?(Numeric))
self.metric = metric
else
LOGGER.warn("metric #{metric} is not a number")
self.metric=0
end
Run Code Online (Sandbox Code Playgroud)
但传入的数字NaN
显然是is_a?(Numeric)
因为我没有得到我的日志警告,它将度量标准传递给我的metric =方法,这是我得到的FloatDomainError
现在,如果我错了,请纠正我,但是如果NaN
(非数字)是Numeric类型,那么在语义上是否错误?谁可以给我解释一下这个?
BTW使用Jruby-1.4.1
我正在尝试使用rspec在我的current_user(使用修改的restful_authentication auth解决方案)上存根方法.我完全不确定如何在我的控制器规范中访问此方法.current_user本身不起作用.我需要首先获得控制器吗?我该怎么做呢?
使用rails 2.3.5
,rspec 1.3.0
和rspec-rails 1.3.2
# my_controller_spec.rb
require 'spec_helper'
describe MyController do
let(:foos){ # some array of foos }
it "fetches foos of current user" do
current_user.should_receive(:foos).and_return(foos)
get :show
end
end
Run Code Online (Sandbox Code Playgroud)
产生
NoMethodError in 'ChallengesController fetches foos of current user'
undefined method `current_user' for #<Spec::Rails::Example::ControllerExampleGroup::Subclass_1::Subclass_1::Subclass_2::Subclass_2:0x7194b2f4>
Run Code Online (Sandbox Code Playgroud) 我无法inverse_of
在创建时加入联合模型.我不确定这是一个错误还是没有实现.我有以下型号:
class Challenge < ActiveRecord::Base
has_many :groups, :through => :group_challenges
has_many :group_challenges, :inverse_of => :challenge
attr_accessor :contact_ids
end
class GroupChallenge < ActiveRecord::Base
belongs_to :challenge, :inverse_of => :group_challenges
belongs_to :group, :inverse_of => :group_challenges
before_save :check_challenge
def check_challenge
Rails.logger.debug("challenge.contact_ids: #{challenge.contact_ids}")
end
end
class Group < ActiveRecord::Base
has_many :challenges, :through => :group_challenges
has_many :group_challenges, :inverse_of => :group
end
Run Code Online (Sandbox Code Playgroud)
contact_ids
是我的虚拟属性challenge
,我想在group_challenges
创建该关联时在模型中访问这些属性.我无法让它发挥作用.这是一个例子:
challenge = Challenge.new :groups => Group.all, :contact_ids => [1,2,3]
# log output => challenge.contact_ids: []
Run Code Online (Sandbox Code Playgroud)
但inverse_of …
我正在使用JavaScript来设置输入的值,其中包含可能包含HTML特定字符的文本&
等等.所以,我试图找到一个匹配这些值的正则表达式并用适当的值替换它们("&" ,"")分别只有我无法弄清楚正则表达式才能做到这一点.
这是我的尝试:
创建一个包含匹配项的对象和对替换值的引用:
var specialChars = {
"&nbsp;" : " ",
"&amp;" : "&",
"&gt;" : ">",
"&lt;" : "<"
}
Run Code Online (Sandbox Code Playgroud)
然后,我想匹配我的字符串
var stringToMatch = "This string has special chars &amp; and &nbsp;"
Run Code Online (Sandbox Code Playgroud)
我试过类似的东西
stringToMatch.replace(/(&nbsp;|&)/g,specialChars["$1"]);
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我真的不明白如何捕获特殊标签并替换它.任何帮助是极大的赞赏.
我已经使用了jquery工具,我开始浏览twitter bootstrap src.
我注意到的一件事是使用$.Event
构造函数来触发事件.
在许多情况下(例如引导模式),您会发现触发的事件如下:
var e = $.Event('show');
this.$element.trigger(e);
Run Code Online (Sandbox Code Playgroud)
我不知道为什么这比直接调用更好:
this.$element.trigger('show');
Run Code Online (Sandbox Code Playgroud)
所以我很想知道使用jQuery Event构造函数有什么好处.我在文档中读到你可以为事件附加任意属性,这对我来说是完全合理的.然而,我不明白的是,如果您根本没有向事件添加任何属性,那么使用构造函数可能是有利的.
有人可以向我解释为什么$.Event
构造函数优于使用事件字符串调用触发器?
非常感谢
我理解instance_eval
和之间的基本区别class_eval
.我玩的时候发现的东西是奇怪的attr_accessor
.这是一个例子:
A = Class.new
A.class_eval{ attr_accessor :x }
a = A.new
a.x = "x"
a.x
=> "x" # ... expected
A.instance_eval{ attr_accessor :y }
A.y = "y"
=> NoMethodError: undefined method `y=' for A:Class
a.y = "y"
=> "y" # WHATTT?
Run Code Online (Sandbox Code Playgroud)
怎么样:
javascript ×3
associations ×2
ruby ×2
activerecord ×1
animation ×1
class-eval ×1
events ×1
google-maps ×1
gwt ×1
jquery ×1
nan ×1
numbers ×1
raphael ×1
regex ×1
rspec ×1
rspec-rails ×1
svg ×1
uibinder ×1