在单个函数中包含sqlalchemy的filter和filter_by函数(Wrap sqlalchemy's filter and filter_by functions in a single function)
我想将函数filter和filter_by包装成单个函数,并根据参数调用filter或filter_by。
该函数必须以这两种方式返回相同的方式运行:
MyModel.get(MyModel.mycolumn == 'value') MyModel.get(mycolumn='value')
有没有办法做到这一点? 谢谢!
I want to wrap the functions filter and filter_by into a single function and call filter or filter_by based on the parameters.
The function must behave in a way that these two would return the same thing:
MyModel.get(MyModel.mycolumn == 'value') MyModel.get(mycolumn='value')
Is there a way to do this? Thank you!
原文:https://stackoverflow.com/questions/17274767
最满意答案
把我的评论转化为答案......
您应该查看浏览器看到的实际HTML(而不是ASP模板代码),因为我认为jQuery不会在HTML中看到ListItem。 HTML中的标准下拉列表是
<option>
标记。 你的ASP可能正在生成那个或其他东西。在浏览器中执行View / Source并查看浏览器实际看到的HTML并将jQuery编码为该。
$('ListItem', this)
可能找不到任何东西。 在编写jQuery来操作它时,你几乎不应该使用ASP代码。 在将ASP模板转换为常规HTML后,您需要知道浏览器实际看到了什么。仅供参考,您的代码的简化版本也可以在下拉列表选择更改时运行,如下所示:
$(document).ready(function () { function checkDropDownList() { if ($("#DropDownList1 option:selected").text() != "a") { $("#select").fadeOut(); } else { $("#select").fadeIn(); } } checkDropDownList(); $("#DropDownList1").change(checkDropDownList); });
没有理由使用
.each()
如果只有一个选定的项目,我们已经知道只有一个DropDownList1
。Turning my comments into an answer...
You should look at the actual HTML that the browser sees (not the ASP template code) because I don't think jQuery sees a ListItem in the HTML. Standard dropdowns in HTML are
<option>
tags. Your ASP might be generating that or something else.Do a View/Source in the browser and look at the HTML that the browser actually sees and code your jQuery to that.
$('ListItem', this)
probably isn't finding anything. You should pretty much never go by the ASP code when writing jQuery to operate on it. You need to know what the browser actually sees after the ASP template has been turned into regular HTML.FYI, a simplified version of your code that also runs any time the drop down list selection is changed works like this:
$(document).ready(function () { function checkDropDownList() { if ($("#DropDownList1 option:selected").text() != "a") { $("#select").fadeOut(); } else { $("#select").fadeIn(); } } checkDropDownList(); $("#DropDownList1").change(checkDropDownList); });
There's no reason to use
.each()
if there can only be one selected item and we already know there's only oneDropDownList1
.
相关问答
更多-
在Web浏览器中首次加载图像时,浏览器下载图像时会出现一定程度的延迟。 一般来说,大多数网站都有很多活动部分。 当浏览器下载HTML文档时,浏览器将开始处理HTML文档中HTML元素表示的所有元素和事件。 例如,当遇到链接标记时,CSS开始加载。 JavaScript正在加载脚本元素。 其他HTML元素添加到DOM。 发生这种情况时,会触发事件,将请求发送到服务器以下载这些资源。 将img标记添加到DOM时,会向服务器发送请求以检索src属性标识的资源。 图像完全下载后,将在页面上呈现。 假设我们正在使用适 ...
-
基本上slideDown()显示图像。 考虑到你的图像在DOM渲染时已经显示出来,没有什么可以向下滑动的。 如果您将样式设置为display:none则使用slideDown() ,它将起作用。 Basically slideDown() shows the image. Considering your image is already shown when the DOM is rendered, there is nothing to slide down to. If you set the sty ...
-
你是对的。 你可以在萤火虫中追踪这个。 在淡出结束时,他将不透明度设置回从他开始的值并display: none 。 你可以通过设置不透明度回到1来解决这个问题,或者当fadeOut完成时更好地设置为'' (对于IE)。 fadeP = $('#fadeP'); clickMe = $('#clickMe'); clickMe.click(function(){ fadeP.stop(true).fadeIn(1000); setTimeout(function(){ fa ...
-
我试过你编码它不适合我,因为我使用系统按钮。 我将按钮的类型更改为自定义,现在可以正常工作(如果预期,我会看到脉冲动画)。 你能验证按钮的类型是自定义的吗? 一般来说,你的方法足够好。 如果您想研究更复杂的动画(不仅仅是按钮),请查看Facebook Pop动画https://github.com/facebook/pop (一些示例https://github.com/hossamghareeb/Facebook- POP教程 ) I tried you code an it didn't work fo ...
-
你已经使用javascript删除了大量的HTML,之后你怎么能显示它? 尝试使用下面的代码,它会工作 $(".newpost-area, .bar-publish").click(function () { //All of this works $(".function-background").fadeIn(700); //$(".function-background").show(); }); $(".ptyper-postbtn").click(function () { ...
-
把我的评论转化为答案...... 您应该查看浏览器看到的实际HTML(而不是ASP模板代码),因为我认为jQuery不会在HTML中看到ListItem。 HTML中的标准下拉列表是
-
您的原始代码工作正常,您在if语句中只有错误的运算符。 不要使用“小于或等于”( <= ),而应使用“大于或等于”( >= )。 if ($containerWidth >= 480) { JSFiddle: http : //jsfiddle.net/d5op9bty/ 我希望这有帮助。 ^^ Your original code works just fine, you just have the wrong operator in your if statement. Instead of usin ...
-
标题单元格中的Javascript Fadein Fadeout文本(Javascript Fadein Fadeout text inheader cell)[2024-02-17]试试以下...... 演示小提琴 $("#editupdate").fadeIn(1000,function(){ var tmp = $(this).html(); $("#editupdate").html('Update').fadeOut(1500, function(){ $("#editupdate").html(tmp).fadeIn(1500); }); }); Try following... Dem ...
在使用jQuery的IE8中使用fadeIn和fadeOut时遇到问题(Having trouble with fadeIn and fadeOut in IE8 with jQuery)[2022-02-18]
嘿,我遇到了同样的麻烦。 我试图淡出一个IE图像并淡入新的东西,像这样: $(".edit_photo_link").click(function(){ $(this).fadeOut("slow", function(){ $(this).next(".throb").fadeIn("slow"); }); }); 哪一个不起作用。 但是FadeIn! 所以猜测这是处理器被IE8(而不是IE7)吃掉了,我只是改变了它: $(".edit_photo_link").click(functi ...您缺少函数声明的括号: setTimeout(function() { }); 注意在function关键字后添加() 。 您需要为fadeIn和fadeOut setTimeout函数执行此操作 You're missing parenthesis for the function declaration: setTimeout(function() { }); Note the addition of () after the function keyword. You need do this ...相关文章
更多- lucene4.7 过滤Filter(六)
- 两种js function 声明方式
- hbase shell使用STARTROW、ENDROW、FILTER查出指定的列
- Filter 简单应用实例求详解
- Solr4:利用Filter实现两组关键词组合查询
- [转]So You Want To Be A Producer
- 线性渐变-linear-gradient和滤镜opacity/filter的透明效果兼容性解决方案及其RGB/RGBA与16进制转换方法
- Solr: a custom Search RequestHandler
- Drupal Forums instead of phpBB or vBulletin: A casestudy
- java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter的解决方案
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。