我正在尝试将某个函数绑定到select字段时将某些东西粘贴到它中(它在允许多个样式和select2:matcher/tokenize后看起来像一个输入字段)但在IE中它总是截断任何包含新行字符的粘贴文本.
<form method="POST" action="/run" class="ui-widget" onsubmit=" return confirmSubmit(this, 'run',true) ">
Editor:
<select name="editor" id="editor" multiple style="width: 200px">
<option>ALL</option>
</select>
<input type="submit" value="Submit">
</form>
Run Code Online (Sandbox Code Playgroud)
bind('paste')似乎没有在一个<select>对象上工作所以我不得不使用bind('change')
var unitIds = ["Red","Yellow","Green"];
$.each(unitIds, function(i, f) {
$('select[name="editor"]').append($('<option>').text(f));
});
$('#pastefromclip').select2({
matcher: function(term, text) {
return text.toUpperCase().indexOf(term.toUpperCase()) === 0;
},
tokenizer: function(input, selection, callback) {
if (input.indexOf(" ") < 0) return;
var parts = input.split(" ");
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
if(part.length > …Run Code Online (Sandbox Code Playgroud) 我有这种格式的多个xml流:
XML1:
<?xml version="1.0" encoding="utf-8"?>
<Node>
<NodeA>test1</NodeA>
<NodeB>test2</NodeB>
<NodeC>
<Att>test4</Att>
<Value1>1.0</Value1>
</NodeC>
</Node>
<Node>
<NodeA>test1</NodeA>
<NodeB>test7</NodeB>
<NodeC>
<Att>test8</Att>
<Value1>2.0</Value1>
</NodeC>
</Node>
...
Run Code Online (Sandbox Code Playgroud)
xmlN:
<?xml version="1.0" encoding="utf-8"?>
<Node>
<NodeA>test1</NodeA>
<NodeB>test2</NodeB>
<NodeC>
<Att>test4</Att>
<ValueN>5.0</ValueN>
</NodeC>
</Node>
<Node>
<NodeA>test1</NodeA>
<NodeB>test7</NodeB>
<NodeC>
<Att>test8</Att>
<ValueN>6.0</ValueN>
</NodeC>
</Node>
<Node>
<NodeA>test9</NodeA>
<NodeB>test8</NodeB>
<NodeC>
<Att>test8</Att>
<ValueN>6.0</ValueN>
</NodeC>
</Node>
Run Code Online (Sandbox Code Playgroud)
我希望合并的xml看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<Node>
<NodeA>test1</NodeA>
<NodeB>test2</NodeB>
<NodeNEW>test4</Att>
<Value1>1.0</Value1>
<ValueN>5.0</ValueN>
</Node>
<Node>
<NodeA>test1</NodeA>
<NodeB>test7</NodeB>
<NodeNEW>test8</NodeNEW>
<Value1>2.0</Value1>
<ValueN>6.0</ValueN>
</Node>
<Node>
<NodeA>test9</NodeA>
<NodeB>test8</NodeB>
<NodeNEW>test8</NodeNew>
<Value1></Value1>
<ValueN>6.0</ValueN>
</Node>
Run Code Online (Sandbox Code Playgroud)
因此,我使用不同的Value1,... ValueN创建唯一键NodeA> NodeB> NodeNEW,如果此唯一键未出现在其各自的xml中,则不分配任何内容.
最有效的方法是什么?
我有这样的数据
Name SortOrder
-------------------
Lower 1 3
Lower 10 2
Lower 2 1
Lower 1% 6
Lower 1.5% 5
Lower 3% 4
Average 7
Upper 1 10
Upper 10 8
Upper 1% 12
Upper 1.5% 11
Average 10 /* sorted
Average Poor 11 * alphabetically
Rich 12 * only */
Min_Low10 17
Min_Low20 18
Min_Low30 19
Min_Up10 20
Min_Up20 21
Min_Up30 22
Run Code Online (Sandbox Code Playgroud)
我想更新排序顺序,这样当我按它排序时,它就像这样
Name SortOrder
-------------------
Lower 3% 1
Lower 1.5% 2
Lower 1% 3
Lower 10 4
Lower 2 …Run Code Online (Sandbox Code Playgroud) 我知道 python 中没有 switch case,可以使用字典代替。但是如果我想将参数传递给函数 zero() 而没有参数给 one() 呢?我没有发现任何与此相关的问题。
def zero(number):
return number == "zero"
def one():
return "one"
def numbers_to_functions_to_strings(argument):
switcher = {
0: zero,
1: one,
2: lambda: "two",
}
# Get the function from switcher dictionary
func = switcher.get(argument, lambda: "nothing")
# Execute the function
return func()
Run Code Online (Sandbox Code Playgroud)
在不必将它们分成两种情况的情况下实现这一点的最简单方法是什么?我认为 func() 需要采用(可选)参数?
我通过逐个创建每个记录从流创建IEnumerable.如果Id已经存在,有没有办法检查我当前的结果,那么我不想将当前读取的记录添加到集合中.
public class Employee
{
public string Name { get; set; }
public string Country { get; set; }
public string Rank { get; set; }
public string Hours { get; set; }
public static Employee Create(IDataRecord record)
{
return new Employee
{
Name = record["name"],
Country = record["country"],
Rank = record["rank"],
Hours = record["hours"],
};
}
}
public IEnumerable<Employee> GetEmployees(TextReader stream)
{
using (var reader = MyLibraryFunction(stream)
{
while (reader.Read())
{
yield return Employee.Create(reader);
}
}
}
var result …Run Code Online (Sandbox Code Playgroud) (def mine '(a b c))
(def yours '(a b))
(remove yours mine)
; should return (c)
Run Code Online (Sandbox Code Playgroud)
有人建议我在另一个线程中使用 remove ,但它不起作用。任何人都可以建议?