刚刚开始使用 Vue.js,需要学习很多东西。我想在禁用输入时更改背景颜色,因为计算函数返回 true。我似乎无法让它发挥作用。
这是我的导出默认值
computed: {
disableField () {
if (condition) return true
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的模板中的
<input
:class="{ disableInput: disableField }"
:disabled="disableField"
/>
Run Code Online (Sandbox Code Playgroud)
这是我的 CSS 中的
.disable-input {
background-color: gray;
}
Run Code Online (Sandbox Code Playgroud)
当计算函数返回 true 时,它会禁用该字段,但不会更改背景颜色。
我有一组事件对象.每个事件都有一个名为location的哈希,其中包含名称,地址,州,城市,邮政编码等密钥.但是并非所有位置都有这些键.我只想显示键的值,如果它们在那里.这是我的代码
@events.each do |event|
if !event.location.empty?
puts "Location: #{event.location[:name]}, #{event.location[:address]}, #{event.location[:city]}, #{event.location[:state]}, #{event.location[:zipcode]}"
end
end
Run Code Online (Sandbox Code Playgroud)
如果我有一个完整的地址,这工作正常.但是,如果我只有它所显示的位置的名称
Location: Central Park, , , ,
Run Code Online (Sandbox Code Playgroud)
我怎样才能摆脱那些多余的逗号?有时它可能是2或3个尾随逗号.我知道如何摆脱一个,但如果没有设置尾随逗号的数量,我不知道该怎么做.希望将位置信息显示在一行上.
任何帮助,将不胜感激.
我想拆分:
array = [["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]]
Run Code Online (Sandbox Code Playgroud)
分成这样的两个哈希:
hash1 = {"a" => "b", "d" => "e", "g" => "h"}
hash2 = {"a" => "c", "d" => "f", "g" => "i"}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我有一个哈希值,它是一个数组。如何以最有效的方式删除数组中的重复元素和相应的ID?
这是我的哈希示例
hash = {
"id" => "sjfdkjfd",
"name" => "Field Name",
"type" => "field",
"options" => ["Language", "Question", "Question", "Answer", "Answer"],
"option_ids" => ["12345", "23456", "34567", "45678", "56789"]
}
Run Code Online (Sandbox Code Playgroud)
我的主意是这样的
hash["options"].each_with_index { |value, index |
h = {}
if h.key?(value)
delete(value)
delete hash["option_ids"].delete_at(index)
else
h[value] = index
end
}
Run Code Online (Sandbox Code Playgroud)
结果应该是
hash = {
"id" => "sjfdkjfd",
"name" => "Field Name",
"type" => "field",
"options" => ["Language", "Question", "Answer"],
"option_ids" => ["12345", "23456", "45678"]
}
Run Code Online (Sandbox Code Playgroud)
我知道我必须考虑到,当我删除options和option_ids的值时,这些值的索引将会改变。但不确定如何做到这一点