小编Ste*_*ose的帖子

谷歌地图v3 API鼠标悬停与多边形?

我正在使用google v3 api构建地图,因为它更快.从本质上讲,它是一个地区的地图,该地区有大约30个城市的多边形区域.当用户在城市上空盘旋时,我希望fillColor变轻,然后在mouseout上返回到它的正常状态.当用户点击时,它会将它们重定向到另一个页面.

点击事件工作得很好.但是,通过v3 API文档,似乎Google已经实现了click,doubleclick,mousemove,mousedown和mouseup作为事件触发器,但没有悬停,鼠标悬停或mouseout.

真?吉兹.我认为一次又一次的优先级高于上下.

无论如何,还有其他人遇到过这个吗?我错了吗?或者有解决方法吗?

提前谢谢你的帮助,斯蒂芬妮

javascript ajax google-maps

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

rails has_one of has_many association

我有一个产品,一个产品可以有很多图像.这是通过关联表.但是,我想要一个产品有一个主图像.

我知道这对模型中的方法很容易,但我希望它是一个关联,以便我可以使用在查询中预加载它include.

楷模:

class Product < ActiveRecord::Base
    has_many :image_associations, :as => :imageable
    has_many :images, :through => :image_associations
end

class ImageAssociation < ActiveRecord::Base
    belongs_to :image
    belongs_to :imageable, :polymorphic => true
end

class Image < ActiveRecord::Base
    has_many :image_associations
end
Run Code Online (Sandbox Code Playgroud)

在ImageAssociation表中,有一个名为"feature"的布尔列,它将图像关联为"主要"图像.

我考虑过这样做的一种方法是main_image_id在products表中添加一列,然后添加到Image模型中:

belongs_to :image, :class => "Image", :foreign_key => "main_image_id"
Run Code Online (Sandbox Code Playgroud)

但是,如果主图像为零,则不允许任何回退到其他has_many图像 - 我希望加载关联.

这就是为什么我希望图像模型中的某些东西像:

has_one :image, :through => :images, :conditions => 'feature = true', :order => 'created_at DESC'
Run Code Online (Sandbox Code Playgroud)

但这给了我一个关联错误.

有没有什么方法可以编辑has_one,或者我是否真的需要运行rake任务将图像推送到每个main_image_id字段,然后为将来的产品添加验证以确保添加了主图像?

编辑:

我应该使用has_and_belongs_to_many协会吗?

activerecord model ruby-on-rails polymorphic-associations

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

用jQuery提升多个父母 - 更有效的方式?

所以,我有一个列表导航,并有子列表和子列表.

基本上,导航默认是折叠的,但是如果人们点击子列表中的页面,我想显示父列表.如果它是子列表的子列表,我需要显示两个父列表.我设置了它,但是,我不喜欢将5 .parent().parent()的内容向上移动以扩展列表.有更有效的方法吗?

HTML:

<div id="lesson-sidebar">
        <ul>
            <li><a href="index.html">Welcome to Beat Basics and Beyond</a></li>
            <li><a href="table-of-contents.html">What's in this course?</a></li>
            <li><a href="defining-your-beat.html" class="active">Defining Your Beat</a>
                <ul>
                    <li><a href="boundaries-of-your-beat.html">Boundaries of Your Beat</a></li>
                    <li><a href="the-beat-description.html">The Beat Description</a></li>
                    <li><a href="build-your-own-beat-description.html"><span class="ital">Activity:</span> Build Your Own Beat Description</a></li>
                </ul>
            </li>
            <li><a href="getting-started.html">Getting Started</a>
                <ul>
                    <li><a href="debrief-your-predecessor.html">Debrief Your Predecessor</a></li>
                    <li><a href="predecessor-top-five-tips.html"><span class="ital">Activity:</span> List The Top Five Tips From Your Predecessor</a></li>
                    <li><a href="covering-your-beat-with-the-internet.html">Covering Your Beat With The Internet</a></li>
                    <li><a href="get-in-the-car-and-go.html">Get in the Car and Go</a></li>
                    <li><a href="mapping-your-beat.html">Mapping Your …
Run Code Online (Sandbox Code Playgroud)

navigation jquery list collapse

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

在WHERE子句中使用REPLACE来检查拼写排列 - MS SQL

我有一张桌子:

| id | lastname | firstname |
|  1 | doe      | john      |
|  2 | oman     | donald    |
|  3 | o'neill  | james     |
|  4 | onackers | sharon    |
Run Code Online (Sandbox Code Playgroud)

基本上,用户将使用姓氏的第一个字母进行搜索.

我希望能够从数据库返回包含和不包含标点符号的结果.例如,当用户搜索:on时

我想两个回复: o'neill,onackers

我希望有人能够搜索"o,on,oneill,oill等"来获取o'neill.

因此,执行此操作的最佳方法似乎是使用lastname列值,并在WHERE子句中使用OR搜索它的两个排列.在SQL中用_替换任何特殊字符的地方,以及所有非alpha字符(包括空格)都消失的字符.

我想我可以在SQL替换中使用下划线来保持一个空间可用.

我在使用WHERE子句时遇到了一些麻烦.我宁愿用一个简单的REPLACE来做这个,而不是在可能的情况下创建一个正则表达式函数.如果那是不合适的,我理解:

@last_name (this is the nvarchar input)

SELECT id, lastname, firstname
FROM people
WHERE ((REPLACE(people.lastname, '[^A-Za-z]', '_') like @last_name + '%')
OR (REPLACE(people.lastnname,'[^A-Za-z ]', '') like @last_name + '%'))
ORDER BY lastname
Run Code Online (Sandbox Code Playgroud)

我很确定更换部件必须位于LIKE的另一侧.我弄乱了结构,但需要一些帮助.

我正在使用MSSQL Server 2005. …

sql sql-server replace where-clause

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

通过PHP从Twitter解码JSON提要不起作用?

所以我通过PHP从JSON格式下载用户的推文.我想把它解码成一个关联数组或至少一些更有用的方式,而不是一个字符串,以便我可以通过它进行操作.

我一直在疯狂阅读json_decode,但对我来说,似乎在我使用它之前和之后,文件的内容仍被检测为一个长字符串.任何人都可以帮我弄清楚我做错了什么?

$url = "http://twitter.com/status/user_timeline/" . $username . ".json?count=" . $count . "&callback=?";    

// $url becomes "http://twitter.com/status/user_timeline/steph_Rose.json?count=5&callback=?";   
        $contents = file_get_contents($url);
        $results = json_decode($contents, true);

        echo "<pre>";
        print_r($results);
        echo "</pre>";

        echo gettype($results); // this returns string
Run Code Online (Sandbox Code Playgroud)

php twitter json decode

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

未初始化的常数 - 控制器内的模型

我有一个俱乐部有多个位置的应用程序.俱乐部及其位置只能在管理员命名空间内编辑.

我正在尝试将俱乐部预加载到控制器中,以便所有操作仅处理该俱乐部.

路线是嵌套的; 但是,在位置控制器中,它找不到Club模型.我究竟做错了什么?

的routes.rb

namespace :admin do
  resources :clubs do
    resources :locations
  end
end
Run Code Online (Sandbox Code Playgroud)

club.rb

class Club < ActiveRecord::Base
  belongs_to :membership
  has_many :users
  has_many :locations
  #accepts_nested_attributes_for :locations
end
Run Code Online (Sandbox Code Playgroud)

管理员/ locations_controller.rb

class Admin::LocationsController < ApplicationController
  before_filter :load_club

  protected 

  def load_club
    @club = Club.find(params[:club_id])
  end
end
Run Code Online (Sandbox Code Playgroud)

另外,最后:我的路线有什么问题,它没有在管理员/俱乐部/位置寻找位置控制器?我不确定这是否是问题的一部分.

来自耙路线

    admin_club_locations POST   /admin/clubs/:club_id/locations(.:format)          admin/locations#create
 new_admin_club_location GET    /admin/clubs/:club_id/locations/new(.:format)      admin/locations#new
edit_admin_club_location GET    /admin/clubs/:club_id/locations/:id/edit(.:format) admin/locations#edit
     admin_club_location PUT    /admin/clubs/:club_id/locations/:id(.:format)      admin/locations#update
                         DELETE /admin/clubs/:club_id/locations/:id(.:format)      admin/locations#destroy
Run Code Online (Sandbox Code Playgroud)

routes ruby-on-rails actioncontroller

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