是否可以选择带插值的元素?我有一个带字符串的var
inputId = "awesomeInput"
Run Code Online (Sandbox Code Playgroud)
我想选择ID为"awesomeInput"的输入.我试着这样做,就像我通常用jquery做的那样
$("#{inputId}")
Run Code Online (Sandbox Code Playgroud)
console.log告诉我已经选择了某些东西,但我试图在这个对象上执行的任何函数都失败了.没有错误,也没有效果.像这样:
$("#{inputId}").show()
Run Code Online (Sandbox Code Playgroud)
如何选择像这样的jquery元素,而不是显示它?
从我所了解的关于LEFT OUTER JOIN的所有内容中,您想要可以为空的表应位于等号的右侧.如果是这种情况,为什么这两个查询都返回相同的结果:
SELECT *
FROM employees e
LEFT JOIN cars c ON c.employeeID=e.id AND c.name='Honda City'
WHERE c.id IS NULL
ORDER BY e.id ASC;
SELECT *
FROM employees e
LEFT JOIN cars c ON e.id=c.employeeID AND c.name='Honda City'
WHERE c.id IS NULL
ORDER BY e.id ASC;
Run Code Online (Sandbox Code Playgroud)
我有一个模态的以下模板
<div class="ui-modal">
<div class="mask"></div>
<div class="ui-modal-container">
<div class="ui-modal-header">
<h3><%= modal['title'] %></h3>
</div>
<div class="ui-modal-text">
<p><%= modal['description'] %></p>
</div>
<% if ( modal['buttons'] !== 'undefined' ) { %>
<div class="ui-button-container">
<a class="ui-button ui-button-pill <%= modal['buttons'][0]['extra_class'] %> " href="<%= modal['buttons'][0]['href'] %>">
<span class="label">
<span class="section"><%= modal['buttons'][0]['label'] %></span>
</span>
</a>
</div>
<% } %>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我试图填充它的数据:
_data = {
"modal" : {
"title" : "Your address is:",
"description" : "Some desc here",
"buttons" : [
{'extra_class': 'small left', 'href' : '#register/3', …Run Code Online (Sandbox Code Playgroud) 我使用postgres的数组数据类型在rails中有一个标记系统.我正在尝试写一个scope会返回任何包含标签的帖子.到目前为止,我有这个范围工作:
scope :with_tag, ->(tag) { where("tags @> ARRAY[?]", tag) }
Run Code Online (Sandbox Code Playgroud)
我想扩展这个范围,以便我可以同时查询多个标签,理想情况如下:
Post.with_tags(['some', 'tags', 'to', 'query'])
Run Code Online (Sandbox Code Playgroud)
哪个会返回任何Post有这些标签的人.我已经考虑过创建一个类方法来处理输入数组的迭代:
def self.with_tags(args)
# start with empty activerecord relation
# want to output AR relation
results = Post.none
args.each do |tag|
results = results.concat(Post.with_tag(tag))
end
results.flatten
end
Run Code Online (Sandbox Code Playgroud)
但这种方法对我来说很有趣,因为它为每个参数创建了一个新的查询.它也不会返回一个ActiveRecord :: Relation,因为flatten我真的希望将它作为输出.
我可以在OR查询范围内完成我所追求的内容吗?
https://jsfiddle.net/e7mcp6xb/
module.exports = Parentheses = (function() {
var _isParenthesesMatch = function(str) {
var parentheses = str.length;
var rightParentheses = '(';
var leftParentheses = ')';
var rightCount = 0;
var leftCount = 0;
for(i=0;i<=str.length;i++){
if(rightParentheses == str.charAt(i))
{
rightCount++;
}
else if(leftParentheses == str.charAt(i))
{
leftCount++;
}
}
if(rightCount == leftCount){
return true;
}
else(rightCount != leftCount){
return false;
}
}
}());
Run Code Online (Sandbox Code Playgroud) 我已将文件中的数据放入数组中,然后我只是保留了我想要的数据,如下所示:
基本上我想要的是独立访问每一列.由于文件将不断变化,我不想要硬编码的东西,我本来已经做到了:).
Element0: | data | address | type | source | disable |
Element1: | 0x000001 | 0x123456 | in | D | yes |
Element2: | 0x0d0f00 | 0xffffff | out | M | yes |
Element3: | 0xe00ab4 | 0xaefbd1 | in | E | no |
我尝试使用正则表达式/\|\s+.*\s+\|/只打印几行(它删除了我关心的数据).我也试过,/\|.*\|/它打印所有空.我用Google搜索了分割方法,我知道发生这种情况是因为.*删除了我关心的数据.我也试过了正则表达式,\|\s*\|但它打印整行.我尝试了许多正则表达式,但此刻我想不出解决这个问题的方法.有什么建议?
`line_ary = ary_element.split(/\|\s.*\|/)
unless line_ary.nil? puts line_ary`
Run Code Online (Sandbox Code Playgroud) 我将不胜感激一些指向如何在ruby方法中的sql语句中解释一些可能微不足道的语法
基本上,功能就像
def foo(param)
connection.execute(<<-SQL ... WHERE tablename.fieldname <@ '#{param.somefield}')
other stuff...
end
Run Code Online (Sandbox Code Playgroud)
我假设'#{param.somefield}'只是在原始sql中输入param的"somefield"字段中的值,但我无法弄清楚"<@"的含义.似乎"<"可以是SQL中的字符串比较运算符,但是"@"在做什么?
谢谢!
我正在使用ruby on rails创建一个博客应用程序.我能够允许用户添加帖子,但在页面顶部,首先创建的帖子首先出现.我希望最新的博客文章首先出现.我该怎么做呢?让我知道我需要在这里添加哪些代码文件.
我的文章控制器
class ArticlesController < ApplicationController
def new
@article = Article.new
end
def index
@articles = Article.paginate(:page => params[:page], :per_page => 10)
end
def show
@article = Article.find(params[:id])
end
def create
@article = Article.new(article_params)
@article.save
redirect_to @article
end
def edit
@article = Article.find(params[:id])
end
def update
@article = Article.find(params[:id])
if @article.update(article_params)
redirect_to @article
else
render 'edit'
end
end
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to articles_path
end
end
private
def article_params
params.require(:article).permit(:title, :text, :datee)
end
Run Code Online (Sandbox Code Playgroud) 我创建了一个 Scheduler() 函数,它将按一定时间间隔执行传递的函数。
func scheduler(what func(), delay time.Duration) {
fmt.Printf("Starting scheduled process on interval %d\n", delay)
ticker := time.NewTicker(delay)
quit := make(chan bool, 1)
go func() {
for {
select {
case <- ticker.C:
what()
case <- quit:
ticker.Stop()
return
}
}
}()
<-quit
}
Run Code Online (Sandbox Code Playgroud)
安排以下 ping 功能可以完美运行。
func ping() {
fmt.Printf("Tick\n")
}
func main() {
scheduler(ping, time.Second)
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我更改 ping 以包含参数,如下所示:
func ping(msg string) {
fmt.Printf ("%s\n", msg)
}
func main() {
scheduler(ping("Hello"), time.Second)
}
Run Code Online (Sandbox Code Playgroud)
我收到编译错误:
ping("Hi") used as …Run Code Online (Sandbox Code Playgroud) postgresql ×3
ruby ×3
jquery ×2
sql ×2
arrays ×1
class ×1
coffeescript ×1
go ×1
html ×1
javascript ×1
regex ×1
templates ×1