我试图从jQuery中的字符串中删除一个字符串.
这是字符串:
username1, username2 and username3 like this post.
Run Code Online (Sandbox Code Playgroud)
我想username1,
从此列表中删除.我尝试使用列表添加列表,.split(', ')
但是我收到了错误.我假设错误是因为不是每个单词后面都有逗号.
我总是想从列表中删除第一项.username1
只是一个用户名示例.如果他们喜欢这篇文章,那么第一项将始终是当前登录用户的用户名.
我试过了:
var updated_list = $('#post_like_list').html().replace('username1, ', '');
$('#post_like_list').html(updated_list);
Run Code Online (Sandbox Code Playgroud)
但那没有更新清单.但它确实在使用时更新了列表.text()
,.html()
但我在列表中有链接,我需要保留.
我正在尝试安装libxml-ruby
.我安装了libxml2
,libxslt
和coreutils
我还阅读了有关该问题的其他帖子,但没有一个解决它.
brew list libxslt
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/bin/xslt-config
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/bin/xsltproc
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/include/libexslt/ (3 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/include/libxslt/ (21 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/libexslt.0.dylib
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/libxslt.1.dylib
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/pkgconfig/ (2 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/ (5 other files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/aclocal/libxslt.m4
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/doc/ (90 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/man/ (3 files)
Run Code Online (Sandbox Code Playgroud)
brew list libxml2
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xml2-config
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xmlcatalog
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xmllint
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/include/libxml2/ (47 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/libxml2.2.dylib
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/cmake/libxml2/libxml2-config.cmake
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/pkgconfig/libxml-2.0.pc
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/ (3 other files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/aclocal/libxml.m4
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/doc/ (153 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/gtk-doc/ (55 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/man/ (4 files)
Run Code Online (Sandbox Code Playgroud)
gem install libxml-ruby
产生以下错误:
Building native extensions. This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed …
Run Code Online (Sandbox Code Playgroud) 我有一个EmberJS应用程序,它由Rails 4 REST API提供支持.应用程序的工作方式很好,但是根据正在执行的查询类型,它变得非常迟缓.
目前API输出如下:
"projects": [{
"id": 1,
"builds": [1, 2, 3, 4]
}]
Run Code Online (Sandbox Code Playgroud)
当用户有许多项目在它们之间分配大量构建时,就会出现问题.EmberJS目前正在查看builds
密钥然后发出请求,/builds?ids[]=1&ids[]=2
这是我想要的行为.
这个问题可能有两种解决方案之一.
我已经尝试了各种有关预先加载的解决方案,并使用序列化程序上的自定义方法手动获取ID.这两个解决方案都添加了许多我不想做的额外代码,并且每个项目仍然会进行单独的查询.
默认情况下,rails SELECT *
在执行has_many时也会执行样式查询,而我无法弄清楚如何在序列化程序层覆盖它.我还写了一个可怕的解决方案,它将整个事情解决了一个快速查询,但它涉及编写原始SQL,我知道这不是Rails的做事方式,我宁愿没有像默认范围这样庞大的复杂不可测试查询.
而不是请求/builds?ids[]=1&ids[]=2
我宁愿不在项目中包含构建密钥,并/builds?project_id=1
在我在Ember中访问该变量时发出请求.我想我可以通过使用类似的东西在每个字段的基础上手动执行此操作:
builds: function () {
return this.store.find('builds', { project_id: this.get('id') });
}.property()
Run Code Online (Sandbox Code Playgroud)
而不是当前:
builds: DS.hasMany('build', { async: true })
Run Code Online (Sandbox Code Playgroud)
值得一提的是,这不仅适用于"构建".项目对象上有4个其他键可以执行相同的操作,因此每个项目有4个查询.
我刚刚升级到Rails 5.在我的规格中,我有以下内容
expect(model).to receive(:update).with(foo: 'bar')
但是,由于params
不再延伸,Hash
但现在ActionController::Parameters
规格正在失败,因为with()
期待哈希,但事实上ActionController::Parameters
有没有更好的方法在Rspec中做同样的事情,比如不同的方法with_hash
?
我可以解决这个问题
expect(model).to receive(:update).with(hash_including(foo: 'bar'))
但这只是检查params是否包含该哈希,而不是检查完全匹配.
是否有任何现有的 ansible 模块可以用于以下用途。我可以等kubectl get nodes
STATUS
= Ready
?
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
master1 NotReady master 42s v1.8.4
Run Code Online (Sandbox Code Playgroud) 我想检查if语句是在一行还是下一行没有括号如下:
if (blah === blah)
do something
Run Code Online (Sandbox Code Playgroud)
要么:
if (foo === foo) do something
Run Code Online (Sandbox Code Playgroud)
我目前的正则表达式是
/\)(?!.*\{)/
Run Code Online (Sandbox Code Playgroud)
但不起作用.有人有主意吗?
要详细说明此正则表达式不会提取的唯一If语句如下:
if (foo === bar)
{
Run Code Online (Sandbox Code Playgroud) 我正在使用标准updated_at
和created_at
桌子.
我的结果是按顺序排列的,updated_at
因为它们可以编辑.
但是,在页面上我正在更新行计数器(视图).这意味着updated_at
将使用新的日期/时间更新,但我想阻止这一点.
有没有办法做到这一点?或者我将不得不created_at
用来订购我的结果?
我宁愿不使用自己的手册created_at
和updated_at
当从控制器使用序列化器时,我可以像这样向它传递额外的选项
render json: user, some_option: 'foobar
Run Code Online (Sandbox Code Playgroud)
然后我可以some_option
在序列化器中引用为
serialization_options[:some_option]
Run Code Online (Sandbox Code Playgroud)
但是,如果我直接调用序列化器
MySerializer.new(user, some_option: 'foobar')
Run Code Online (Sandbox Code Playgroud)
我无法获得额外的选项,因为serialization_options
它是一个空对象。
我有许多需要重复填写的输入字段,因此我通常用它Tab来浏览表单。
字段具有需要前置的默认后缀值。当我通过鼠标单击将焦点集中在输入上时,它会按预期工作。
但是,当我在输入之间切换时,它会选择所有文本,这在我的情况下是不良行为。
看看这个:
function setCaretPosition(elem, caretPos) {
if (elem == null) return;
if (elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', caretPos);
range.select();
} else if (elem.selectionStart) {
elem.focus();
elem.setSelectionRange(caretPos, caretPos);
} else {
elem.focus();
}
}
$(document).ready(function() {
$('input').focus(function() {
setCaretPosition(this, 0);
});
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="input1" value=" km/h" />
<input type="text" id="input2" value=" kg" />
Run Code Online (Sandbox Code Playgroud)
使用选项卡导航时如何防止文本输入突出显示其内容?
setTimeout
我更喜欢不使用(如果可能的话)的答案。
javascript ×3
kubernetes ×2
php ×2
activemodel ×1
amazon-eks ×1
ansible ×1
ember.js ×1
homebrew ×1
html ×1
jquery ×1
laravel ×1
libxml-ruby ×1
libxml2 ×1
macos ×1
mysql ×1
performance ×1
regex ×1
rspec ×1
ruby ×1
rubygems ×1
sql ×1
string ×1