有没有办法将动态参数传递给自定义jquery验证方法?具体来说,我正在寻找一种方法来比较2个控件,并希望将一个控件传递给另一个的验证方法进行比较.
这是我目前拥有的:
//Add method
$.validator.addMethod("lowerInt", function(value, element, params) {
alert('inside method');
if (isNaN(parseInt(params)))
return true;
else
return parseInt(value) < parseInt(params);
}, $.validator.format("Please enter a number smaller than {0}"));
//Set validation
$("#form1").validate({
rules: {
lowInt: {
required: true,
integer: true,
lowerInt: 8 //I would like to pass a dynamic value here
}
}
});
Run Code Online (Sandbox Code Playgroud)
如果我按上述方式运行它,它可以正常工作.如果我将传入lowerInt的8更改为$('#highInt').val(),它似乎只设置了一次lowerInt函数的值,并且从不更新它.我意识到我可以通过调用$('#highInt').val()来获取方法中的值,但是如果可能的话我想传递该值.
我必须一次向redis插入~80,000行,并且正在研究使用redis流水线操作.但是,当仅插入1000行进行测试时,使用流水线操作需要46秒,而没有流水线操作需要6秒.
在下面的代码中,我有一个按邮政编码分组的邮政编码列表,我试图插入到redis中.它们作为RedisZipCode插入,其中包含作为id的zipcode和在分组期间收集的zipcodes列表.
public class ZipCode
{
public string city { get; set; }
public string state { get; set; }
public string zip_code { get; set; }
}
public class RedisZipCode
{
public string id { get; set; }
public List<ZipCode> zipcodes{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
没有流水线
using (var zipCodeClient = redisClient.GetTypedClient<RedisZipCode>())
{
foreach (var item in zipcodes.GroupBy(z => z.zip_code))
{
zipCodeClient.Store(new RedisZipCode(item.ToList()));
}
}
Run Code Online (Sandbox Code Playgroud)
使用Pipelining
using (var zipCodeClient = redisClient.GetTypedClient<RedisZipCode>())
using (var pipeline = zipCodeClient.CreatePipeline())
{
foreach (var item …Run Code Online (Sandbox Code Playgroud) 我想通过JavaScript手动将搜索应用到我的jqGrid.我在这里尝试了一个指南,但似乎无法让它完全正常工作.在网格设置中,我有一个名为'error_column'的列,我想在搜索字符串'Test'时执行搜索.
这是我到目前为止:
var filter = { "field": "error_column", 'oper': 'eq', "data": 'Test' };
$("Grid2").jqGrid('setGridParam', { search: true, postData: { filters: filter} })
$("Grid2").trigger('reloadGrid');
Run Code Online (Sandbox Code Playgroud)
当我单击这个绑定的按钮时,没有任何反应,它不会导致错误.
编辑 以下是初始化网格的代码:
jQuery("#Grid2").jqGrid({
datatype: "local",
height: 250,
colNames: ['NewSubscriberID', 'Conflicting Subscriber ID', 'Error Field', 'Error Message'],
colModel: [
{ name: 'new_subscriber_id', index: 'new_subscriber_id', width: 120},
{ name: 'conflicting_subscriber_id', index: 'conflicting_subscriber_id', width: 170},
{ name: 'error_column', index: 'error_column', width: 90, sorttype: "text", search: true},
{ name: 'error_type', index: 'error_type', width: 145}
],
loadonce: true
}); …Run Code Online (Sandbox Code Playgroud)