我已经看过几个关于bootstrap模态的问题,但没有一个完全像这样,所以我会继续.
我有一个模态,我打电话就像这样......
$(".modal-link").click(function(event){
$("#modal-content").modal('show');
});
Run Code Online (Sandbox Code Playgroud)
这工作正常,但是当我显示模态时我想要关注第一个输入元素...在可能的情况下,第一个输入元素的id为#photo_name.
所以我试过了
$(".modal-link").click(function(event){
$("#modal-content").modal('show');
$("input#photo_name").focus();
});
Run Code Online (Sandbox Code Playgroud)
但这无济于事.最后,我尝试绑定到'show'事件,但即便如此,输入也不会集中.最后只是为了测试,因为我怀疑这是关于js加载顺序,我放入一个setTimeout只是为了看看我是否延迟了一秒,焦点是否有效,是的,它有效!但这种方法显然是废话.有没有办法在不使用setTimeout的情况下获得与下面相同的效果?
$("#modal-content").on('show', function(event){
window.setTimeout(function(){
$(event.currentTarget).find('input#photo_name').first().focus()
}, 0500);
});
Run Code Online (Sandbox Code Playgroud) 我是Docker的新手并试图制作一个演示Rails应用程序.我做了一个看起来像这样的dockerfile:
FROM ruby:2.2
MAINTAINER marko@codeship.com
# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \
build-essential \
nodejs
# Configure the main working directory. This is the base
# directory used in any further RUN, COPY, and ENTRYPOINT
# commands.
RUN mkdir -p /app
WORKDIR /app
# Copy the Gemfile …Run Code Online (Sandbox Code Playgroud) 我有一个骨干视图模型,我在这里渲染,并使用jquery ui使其可拖动.
render: ->
$(this.el).attr('class', 'item').html(this.template(this.options.model.toJSON() ))
viewmodel = this
$(this.el).draggable
revert: true
drag: () ->
console.log(viewmodel)
Run Code Online (Sandbox Code Playgroud)
上面,我有viewmodel可用,可以从dom中删除它,在模型上调用方法等等.但我想要的是将这个视图模型拖入一个可放置的容器 - 就像一个垃圾桶 - 然后调用一些视图模型的方法并将其从DOM中删除.
我看到的是,当一个项目被放入容器时的回调方法是:
$(function() {
$("#trash").droppable({
drop: function(event, ui) {
console.log(ui.draggable);
}
});
});
Run Code Online (Sandbox Code Playgroud)
所以,我能够看到ui.draggable并从DOM中删除它,但我没有参考它的视图模型.难道我做错了什么?有办法解决这个问题吗?
jquery-ui backbone.js jquery-ui-draggable jquery-ui-droppable
我在Active Record文档中看到,您可以使用大于/小于比较来查询日期.但是,如果你想选择date = Date.today,或者我必须查询哪里的日期大于昨天而不是明天?
正如您所看到的,我在以下查询中正是这样做并查询Date = today返回空集的位置
1.9.3p286 :096 > Subscription.where("created_at = ?", Date.today).count
(0.5ms) SELECT COUNT(*) FROM `subscriptions` WHERE (created_at = '2013-01-18')
=> 0
Run Code Online (Sandbox Code Playgroud)
与
1.9.3p286 :098 > Subscription.where("expiration_date < ? AND expiration_date > ?", Date.today + 1, Date.today - 1).count
(0.4ms) SELECT COUNT(*) FROM `subscriptions` WHERE (expiration_date < '2013-01-19' AND expiration_date > '2013-01-17')
=> 1
Run Code Online (Sandbox Code Playgroud)
这是查询今天日期的正确方法还是我错过了什么?
我有两个问题.
我是否错误地假设我的所有javascripts都应该在rails 3.1中被压缩成application.js,即使在开发模式下也是如此?
如果没有,那么为什么我的标签包含我的所有30个javascripts并且需要加载?
我的application.js文件如下所示:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
在浏览器中,它呈现为:
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the …Run Code Online (Sandbox Code Playgroud) 我正在尝试在整个网站中优化我的查询.
我有3个模特,照片,人物,外观
照片has_many出场,很多人通过外观Appearances表只有一个person_id,photo_id
现在,如果我要搜索"人物"并且我想加载他们的外观和照片,我会做这样的事情:
Person.joins(:appearances => :photo).limit(5)
Run Code Online (Sandbox Code Playgroud)
现在,我不确定这是否理想,但假设我的人有外观属于照片,而照片又有外观和其他人.我甚至不知道你是否或如何在vanilla SQL中执行此操作,但我只是好奇这是否可行.
Person.joins(:appearances => :photo => :appearaces => :person).limit(5)
Run Code Online (Sandbox Code Playgroud)
这种语法会导致错误,同样,我只是好奇,我正在处理我的视图中的照片的外观和人物,我只是想试验加载时间,看看这是否可能.
我有两个模型:Page和Department.我在extjs的列表视图中显示页面,我想在List视图中显示Department的Name而不是department_id.我没有实际将部门添加到页面VIA GUI,只是通过直接的db insert语句,但我想至少能够在列表视图中显示部门名称.
到目前为止,我有以下内容,这是显示department_id
Ext.define('ExtMVC.model.Department', {
extend: 'Ext.data.Model',
fields: ['name']
});
Ext.define('ExtMVC.model.Page', {
extend: 'Ext.data.Model',
fields: ['title','body','department_id'],
associations: [
{type: 'belongsTo', model: 'Department'}
]
});
Run Code Online (Sandbox Code Playgroud)
Ext.define('ExtMVC.store.Pages', {
extend: 'Ext.data.Store',
model: 'ExtMVC.model.Page',
autoLoad: true,
proxy: {
type: 'rest',
url: '/admin/pages',
format: 'json'
}
});
Ext.define('ExtMVC.store.Departments', {
extend: 'Ext.data.Store',
model: 'ExtMVC.model.Department',
autoLoad: true,
proxy: {
type: 'rest',
url: '/admin/departments',
format: 'json'
}
});
Run Code Online (Sandbox Code Playgroud)
Ext.define('ExtMVC.view.page.List' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.pagelist',
title : 'All Pages',
store: 'Pages',
initComponent: function() { …Run Code Online (Sandbox Code Playgroud) 如果我有一个具有多个域的服务器,那么在同一个域上实现单点登录解决方案的首选方法是什么.我目前正在使用设计,在不同的域上有几百万个cookie,并且卡住了.除了实施SSO之外,我还需要将各种cookie迁移到中央域.关于各种服务器,它们只有一个页面,要求我根据用户是否登录显示不同的状态.
我尝试过以下方法:
CORS:选择一个域作为中央身份验证中心.从所有其他域进行跨域检查以查看用户是否已登录.对于迁移cookie,检测是否存在"current_user"对象,将其发送到客户端,发出CORS请求,签署用户并终止令牌.效果很好!但是......在建立2-3周之后,它在IE中完全失败了.即使是IE11,我注意到默认设置是禁用此行为.
试图修改会议商店
Rails.application.config.session_store
Run Code Online (Sandbox Code Playgroud)没有运气.
我目前正在尝试以下方面:
JSONP:我现在有人尝试将上面的内容转换为JSONP,而我尝试了其他一些选项:
设置自定义OAUTH提供程序.像以前一样,如果此人登录,它将成为"中心域",使用用户可以发出请求的令牌返回请求的域.https://github.com/songkick/oauth2-provider
看着这个,但它看起来过时了?https://github.com/rubycas/rubycas-client.我也觉得这可能是一个解决方案,如果我从一开始就推出这个,但考虑到我们进入项目的程度,我不清楚我如何转移现有的cookie.此外还不清楚这是否需要两个应用程序让我启动并运行(一个用于客户端,一个用于auth服务器)
当我经历这些可能性时,如果有人有任何经验做我正在做的事情,请告诉我并为我节省大量工作:)
好的,所以我有一个导航和仪表板的概念.在我的路由器中单击导航链接时,我正在调用仪表板视图来设置活动选项卡.
例如:
<a href="#" class="dashabord_tab" id="widgets">Widgets</a>
<a href="#" class="dashabord_tab" id="Foobars">Foobars</a>
Run Code Online (Sandbox Code Playgroud)
<div id="nav"></div>
<div id="current_tab"></div>
Run Code Online (Sandbox Code Playgroud)
DashboardView = Backbone.View.extend({
template:JST.dashboard_container,
render: function(){
$(this.el).html(this.template());
},
activateWidgets: function(){
if(!(this.widgets_view)){
this.widgets_view = new WidgetsView();
this.widgets_view.render();
}
$(this.el).find("#current_tab").html(this.widgets_view.el);
},
activateFoobars: function(){
if(!(this.foobars_view)){
this.foobars_view = new FooBarsView();
this.foobars_view.render();
}
$(this.el).find("#current_tab").html(this.foobars_view.el);
}
});
Run Code Online (Sandbox Code Playgroud)
因此,当我第一次切换到widgets_tab或foobar_tab时,选项卡会按预期加载.但是,如果我切换到选项卡,切换它,然后切换回它,我视图中的所有事件都不再绑定.点击,欢迎,foobars_view中的任何视图都不是可点击的,可以浏览的等等.
在过去,我一直在为每个子视图创建一个包装器,如下所示:
activateFoobars: function(){
$('.tab_wrapper').hide();
if($(this.el).find("#foobars_wrapper").length < 1){
$(this.el).append("<div class='tab_wrapper' id='foobars_wrapper'></div>");
this.foobars_view = new FooBarsView();
$(this.el).find("#foobars_wrapper").html(this.foobars_view.render().el);
}
$('#foobars_wrapper').show();
}
Run Code Online (Sandbox Code Playgroud)
我宁愿不按照上面所示的方式去做,而且我真的很想把视图的el放在一个始终保持开放的active_tab div中...如果我不能按照我喜欢的方式去做to,有没有替代我上面展示的方式?谢谢!
我有一个在Cucumber中分配给我的故事列表,其中一个是"然后用户应该收到确认电子邮件".我认为用户收到它的测试超出了应用程序的功能,但我如何测试刚刚发送的电子邮件?
activerecord ×2
backbone.js ×2
actionmailer ×1
cookies ×1
cors ×1
cucumber ×1
devise ×1
docker ×1
email ×1
extjs ×1
extjs-mvc ×1
extjs4 ×1
javascript ×1
jquery ×1
jquery-ui ×1
jsonp ×1
modal-dialog ×1