我希望我的表中的替代行被着色.什么是最好的方法,javascript,rails?
今天,我做了一个简单的<%num%2%>,但这是一个常见的操作,我认为应该有一个更聪明的方法来做到这一点
我很困惑ajax:在使用之前:jquery-ujs/rails.js
1)是否等待ajax中的任何给定函数:在继续之前完成之前?
2)如果某个条件失败,如何在jQuery中完全取消该事件?(我似乎没有指向事件的指针)
-
更新:我试过这个,这通常有效,但现在不行.= |
.bind('ajax:before', function(evt){
evt.stopImmediatePropagation();
} )
//also tried preventDefault, stopPropagation, etc
Run Code Online (Sandbox Code Playgroud) 当旧的facebox关闭时,我需要触发一个新的facebox.
这就是我现在这样做的方式,但我觉得可以有更优雅的方式.
function process(){
Run Code Online (Sandbox Code Playgroud)step1(step2); //triggers the first facebox function step1(cb){ $.facebox(1); $("#facebox .finished").click(function(event){ cb(); }); }; function step2(){ $.facebox(2); } }
a=[1,2,3,4,5]
b=[4,3]
array_wanted=[4,3,1,2,5]
Run Code Online (Sandbox Code Playgroud)
我可以通过映射和推动来做到这一点,但我很想知道更优雅的方式.
我为chrome中的下拉列表设置了字体大小,但它似乎没有改变大小 <select>
它适用于FF - 当我将字体大小设置为15px时,它的区别更大
我需要在mongo中将无序的ID列表存储为"黑名单",并将它们纯粹用于检查原因.
blacklisted_ids= [1,23......100002942234... some very large number]
Run Code Online (Sandbox Code Playgroud)
但是将其存储在单个文档中是不可行的,因为我将非常快地完成2Mb的限制.
我可以在mongodb中创建一个集合,并将每个id作为文档插入,但它似乎有点矫枉过正,因为我想要的只是检查是否存在.
这样做的正确方法是什么?
注意:我使用的是mongoid/rails.=)
以
NSURL *url = [NSURL URLWithString:@"eg://resources/users/1/answers/2"];
NSLog(@"%@", [url pathComponents]);
>> ( "/", "users", "a", "answers", "b" )
Run Code Online (Sandbox Code Playgroud)
1)为什么路径包含“/”?
2)如果我想要的是“用户”,使用第一个索引是否安全?
[[url pathComponents] objectAtIndex:1];
Run Code Online (Sandbox Code Playgroud) 我试图用json将json字符串转换为对象.
我在下面有一个非常简单的例子,它运行,但结果答案是空的,即:我的答案对象的文本字段为空.
import com.google.gson.*;
public class Meow {
public static void main(String[] args) throws Exception{
Gson gson = new Gson();
String jsonOutput = "[{\"answer\":{\"text\":\"text1\"}},{\"answer\":{\"text\":\"text2\"}} ]";
Answer[] a = gson.fromJson(jsonOutput, Answer[].class);
for(Answer i:a) {
System.out.println(i.text);
}
}
public class Answer {
public String text;
public Answer(String text) {
super();
this.text=text;
}
public String toString(){
return text;
}
public void setText(String a){
this.text=a;
}
}
}
Run Code Online (Sandbox Code Playgroud) 这是错误:
迁移代码:
class Test < ActiveRecord::Migration
def change
create_table :test do |t|
end
end
end
Run Code Online (Sandbox Code Playgroud)
作为旁注,如果我删除"Create_table"调用它不会失败.
运行时rake db:migrate,我收到此错误消息:
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `each_pair' for []:Array/Users/m/Apps/stream-web/db/migrate/20150329070040_test.rb:3:in `change'
NoMethodError: undefined method `each_pair' for []:Array
/Users/m/Apps/stream-web/db/migrate/20150329070040_test.rb:3:in `change'
Run Code Online (Sandbox Code Playgroud)
怎么可能解决这个问题?我正在使用"pg"gem,我的适配器是postgresql.
完全跟踪错误:
undefined method `each_pair' for []:Array/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:216:in `create_table'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/schema_plus-1.8.5/lib/schema_plus/active_record/connection_adapters/schema_statements.rb:39:in `create_table_with_schema_plus'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:662:in `block in method_missing'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:632:in `block in say_with_time'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:632:in `say_with_time'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:652:in `method_missing'
/Users/mingyeowng/Apps/stream-web/db/migrate/20150329070040_test.rb:3:in `change'
Run Code Online (Sandbox Code Playgroud) 我将换行符存储为数据库中的"line \n \nline".
当我显示它时,我使用此方法转换它:
def showLineBreaks(from_textarea)
from_textarea.gsub(/\n/,"<br/>")
end
Run Code Online (Sandbox Code Playgroud)
但是这些将文本呈现为
line<br><br>line
Run Code Online (Sandbox Code Playgroud)
而不是显示换行符.
这样做的正确方法是什么?