更确切地说,我试图完成的是,当我拖动谷歌地图时,谷歌地图标记 始终固定在地图的中心.在我看来,这将改善用户体验,这就是我现在正在做的事情:
var map, marker, options;
options = {
center: new google.maps.LatLng(latitude, longitude),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
overviewMapControl: false,
zoomControl: true,
draggable: true
};
map = new google.maps.Map(mapContainer, options);
marker = new google.maps.Marker({
position: new google.maps.LatLng(latitude, longitude),
map: map,
animation: google.maps.Animation.DROP
});
//This line is what makes the Marker stick to the center of the map
marker.bindTo('position', map, 'center');
Run Code Online (Sandbox Code Playgroud)
我在上面的代码中遇到的问题是......当我在Marker下面拖动地图时,它不够平滑,即.拖动结束时,Marker 从"最后"中心跳到 "新"中心.(这在移动设备上更明显),因此我需要的是标记真的永久固定在其地图中心.
有办法完成这项工作吗?(我想我曾经在一个网站上看过这个)
让我知道如果你们可以帮助我.
谢谢.
老实说,我试图覆盖Backbone的一个Model的sync()方法,我有适当的函数签名,并且它被正确触发,但我不知道在函数体中放入什么命令它默认调用DELETE但有额外的参数.即.
class Master.Models.Member extends Backbone.Model
urlRoot: '/api/members/'
sync: (method, model, options) ->
params = _.clone options
Backbone.sync method, model, params
Run Code Online (Sandbox Code Playgroud)
我称之为:
......
remove: ->
@model.destroy
collective_id: the_id
Run Code Online (Sandbox Code Playgroud)
我的目的是将你在那里看到的collective_id param 传递给服务器.但即使它在sync()的选项哈希中,我克隆它,它也不会进入服务器! 如何将额外的参数发送到服务器?
(实际上,到达服务器的唯一东西是Model的id)
提前致谢!
简单地说,我只想知道是否有办法使用Ransack gem设置排序功能的默认值?即.
目前,页面加载时我有以下内容:
但相反,我希望在页面加载时具有以下默认值:
是否可以通过正确配置Ransack宝石来实现这一目标?
一如既往地感谢!
最好的祝福!
考虑到在Ruby编程语言中,一切都被称为对象,我安全地假设将参数传递给方法是通过引用完成的.然而,下面这个小例子让我困惑:
$string = "String"
def changer(s)
s = 1
end
changer($string)
puts $string.class
String
=> nil
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,原始对象未被修改,我希望知道为什么,以及如何实现所需的行为,即.获取方法实际更改其参数引用的对象.
在Coffeescript中使用课程时,我偶然发现了一个重大问题,让我来说明一下
class Bet
constructor: () ->
placeBet: ->
$('#chips > div').bind 'click', ->
amount = $(this).attr 'id'
pile = $(this)
switch amount
when "ten" then this.bet pile, amount #This line causes a problem
bet: (pile, amount) ->
alert 'betting!'
Run Code Online (Sandbox Code Playgroud)
上面对this.bet的调用会产生以下错误:
未捕获的TypeError:对象#没有方法'下注'
所以,目前我的类的实例方法没有被调用,如何在没有与jQuery选择器碰撞的情况下正确调用我的类的bet方法(这是我现在想要发生的事情)?
非常感谢你提前!
我最近读到在JavaScript中嵌入ruby 并不是一个好主意. 然而,在诸如David Heinemeier Hansson的带有Rails的敏捷Web开发这样的书中,这正是它所做的.如果用JS嵌入ruby不是一个好主意,那么这种情况的最佳实践是什么? 给出一些简单的东西:(jQuery + ruby)
posts_controller
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
format.js #will use this response to process ajax
else
format.html { render :action => "new" }
end
end
end
Run Code Online (Sandbox Code Playgroud)
create.js.erb
$tr = $('<tr>');
$td1 = $('<td>').text('<%= @post.title %>');
$td2 = $('<td>').text('<%= @post.content %>');
$tr.append($td1, $td2);
$('table tbody').append($tr);
Run Code Online (Sandbox Code Playgroud)
应该如何重构以遵循不用JS嵌入ruby的"最佳实践"?(如果是这种情况)
我真的需要对此有所了解,也许正确的概念是因为我已经读过rails 3.1将JS完全通过资产从Ruby中分离出来?(这是正确的吗?)
谢谢 !
我现在正在转向使用Coffeescript编写我的所有javascript代码,但我很沮丧因为最简单的例子导致我出现问题.截至目前,我已经做了一个多小时的研究而没有找到答案...
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js" type="text/javascript" charset="utf-8"></script>
<link href="sheet.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/coffeescript">
$ ->
sayHi()
sayHi = ->
alert 'Hi there!'
</script>
</head>
<body>
<div id="all">
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
从上面的代码可以清楚地看出,我只是试图从jQuery的ready处理程序中调用sayHi()函数.但我得到的错误如下:
未捕获的TypeError:undefined不是函数
请帮助我,根据编译器和教程,我已经读过这个' 应该 '的工作,但我不知道我在做什么可怕的错误为此不运行:(
我使用的是新水豚DSL使用RSpec以下位于短方针这里
并添加到测试spec/features
目录中运行以及单独的,即.
rails_project$ rspec spec/features/my_first_feature.rb
然而,spec/features
目录完全忽略了,当我尝试运行整个测试spec/
这样的目录:
rails_project$ rspec .
指南中没有提到如何包含这个目录(或其他目录)来完成我想要的包含.我真的需要这个来持续集成我的项目.
有人可以告诉我怎么做吗?
谢谢!
我目前正在尝试转换这个ruby数组:
[5, 7, 8, 1]
Run Code Online (Sandbox Code Playgroud)
进入这个:
[[5], [7], [8], [1]]
Run Code Online (Sandbox Code Playgroud)
什么是最好的方式?
我现在这样做:
[5, 7, 8, 1].select { |element| element }.collect { |element| element.to_a }
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
警告:默认`to_a'将过时
我究竟做错了什么?你能告诉我如何做到这一点吗?
在此先感谢您的问候!
我正在使用非常酷的ng-map库for angular,我想知道如何访问ng-map marker指令引用的基础标记对象
所以,我有这个标记:
<div id="map-search" data-tap-disabled="true">
<map zoom="15" disable-default-u-i="true">
<marker ng-repeat=" pos in positions" position="{{pos.latitude}}, {{pos.longitude}}" id="{{pos.index}}" on-click="pinClicked()">
</marker>
</map>
</div>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我没有找到在点击事件期间访问Google Maps Marker对象的直接方式; 从控制器:
app.controller('MapSearchController', function($scope) {
$scope.$on('mapInitialized', function(event, map) {
$scope.map = map;
//Assume existence of an Array of markers
$scope.positions = generatePinPositionsArray();
});
$scope.pinClicked = function(event, marker) {
console.log('clicked pin!');
//HOW CAN I GET THE MARKER OBJECT (The one that was clicked) HERE?
console.log('the marker ->', marker); //prints undefined
}; …
Run Code Online (Sandbox Code Playgroud) ruby ×5
coffeescript ×3
javascript ×3
jquery ×3
google-maps ×2
angularjs ×1
arrays ×1
backbone.js ×1
capybara ×1
mobile ×1
ng-map ×1
ransack ×1
rspec ×1
rspec-rails ×1
testing ×1