同一 Pyramid 页面上的 JQueryUI 自动完成的多个实例
我有一个有效的 JQueryUI 自动完成输入小部件,可以与我的 Pyramid 后端很好地配合。自动完成将其 request.params['term']
发布到与其所在页面相同的 URL,并且 Pyramid 使用 request_param='term'
作为发送的路由谓词我的数据库查询的术语值可查看可调用。
但我现在遇到的问题是,我需要向同一页面添加更多自动完成小部件。但是,我无法使用相同的路由谓词 term
,因为两个小部件都会发布 term
,因此 Pyramid 不知道将帖子发送到哪里。
我知道您可以在 Pyramid 中创建自定义谓词,但据我所知,我可以用来创建自定义谓词的 2 个自动完成小部件没有什么独特之处。
为了提供一些上下文,下面是路由/视图定义。这个定义实际上是非法的,因为 Pyramid 正确地拒绝了相同的谓词,但它证明了我的困境:
config.add_route('search_programs','/search/programs')
config.add_view(
'haystack.search.search_programs',
route_name='search_programs',
renderer='templates/search_programs.jinja2')
config.add_view(
'haystack.search.programtype_autocomplete',
route_name='search_programs',
request_param='term', renderer='json')
config.add_view(
'haystack.search.majorgenre_autocomplete',
route_name='search_programs',
request_param='term', renderer='json')
如果自动完成小部件有一个选项来指定用于发布的任意键,而不是每次都只指定“术语”,那就太棒了。任何帮助都会很棒。
I have a working JQueryUI Autocomplete input widget working nicely with my Pyramid backend. The autocomplete posts its request.params['term']
to the same URL as the page its on, and Pyramid uses request_param='term'
as a route predicate to send the term value to my database query view-callable.
The problem I have now though, is that I need to add more autocomplete widgets to the same page. However, I can't use the same route predicate term
because both widgets post term
and so Pyramid doesn't know where to send the post.
I know you can make custom predicates in Pyramid, but as far as I can see, there is nothing unique about the 2 autocomplete widgets with which I can make a custom predicate.
To give some context, below is the route/view definition. The definition is actually illegal because Pyramid rightly refused to identical predicates, but it serves to demonstrate my dilemma:
config.add_route('search_programs','/search/programs')
config.add_view(
'haystack.search.search_programs',
route_name='search_programs',
renderer='templates/search_programs.jinja2')
config.add_view(
'haystack.search.programtype_autocomplete',
route_name='search_programs',
request_param='term', renderer='json')
config.add_view(
'haystack.search.majorgenre_autocomplete',
route_name='search_programs',
request_param='term', renderer='json')
What would be awesome is if the autocomplete widget had an option to specify an arbitrary key for posting, instead of just 'term' every time. Any help would be awesome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为每个小部件显式设置
自动完成
,并在帖子中指出特定的网址和/或自定义数据。这是来自 JQueryUI 文档上的 远程 JSONP 数据源 示例的剪辑:
然后您可以在 Pyramid 中按照你想要的方式处理它。我可能只会将一个视图映射到这条路线(而不用担心 ajax
customParam
):然后在视图中:
You need to set your
autocomplete
for each widget explicitly and indicate a specific url and/or a custom piece of data in the post.This is a clip from the Remote JSONP datasource example on the JQueryUI documentation:
Then you can handle it in Pyramid however you want. I would probably just map one view to this route (and not bother with an ajax
customParam
):And then in the view: