首页 \ 问答 \ 在单个函数中包含sqlalchemy的filter和filter_by函数(Wrap sqlalchemy's filter and filter_by functions in a single function)

在单个函数中包含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
更新时间:2022-07-04 21:07

最满意答案

把我的评论转化为答案......

您应该查看浏览器看到的实际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 one DropDownList1.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。