python - 在 Python 3.8 中 - 如何从 RecycleView 中搜索我的小部件名称
问题描述
如何执行该search
功能取决于我输入的内容textfield
?如果我输入的文本textfield
等于RecycleView data['name']
,如何让那个唯一的小部件显示?
KV = '''
<Card>:
AsyncImage:
source: root.source
ScreenManager:
id: screen_manager
screen_manager: screen_manager
Screen:
name: 'main'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Card List"
elevation: 10
pos_hint: {'top': 1}
MDIconButton:
icon: 'magnify'
pos_hint: {'center_y': .5}
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
on_release: root.screen_manager.current = 'search'
RecycleView:
id: rv
key_viewclass: 'viewclass'
RecycleGridLayout:
cols: 3
padding: dp(17), dp(20)
spacing: dp(15)
size_hint_y: None
height: self.minimum_height
default_size: dp(95), dp(135)
default_size_hint: None, None
orientation: 'vertical'
Screen:
name: 'search'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Search"
elevation: 10
pos_hint: {'top': 1}
MDIconButton:
icon: 'arrow-left'
pos_hint: {'center_y': .5}
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
on_release: root.screen_manager.current = root.screen_manager.previous()
ScrollView:
MDGridLayout:
cols: 1
padding: dp(20), dp(20)
spacing: dp(15)
size_hint_y: None
height: self.minimum_height
MDTextField:
id: search_field
hint_text: "Search"
icon_right: 'magnify'
MDRaisedButton:
text: "Search"
on_release: app.pressed()
'''
class Card(MDCard):
name = StringProperty()
source = StringProperty()
owner = ObjectProperty()
class Testing(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
with open('images.json') as f:
image_data = f.read()
images = json.loads(image_data)['PRD'].items()
self.root.ids.rv.data = [{'viewclass': "Card", 'name': k, 'source': v, 'owner': self} for k,v in images]
def pressed(self):
self.root.ids.search_field.text = ''
解决方案
推荐阅读
- reactjs - 从复选框中获取名称和当前值:react js
- java - 如何在执行器端点中自动装配 FactoryBeans
- java - 我无法启动从 spring-boot docker maven 插件构建的 docker 映像
- sql - 如何授予执行权限但不插入更新删除
- reactjs - React 中的工具提示在悬停时显示在单个框中
- python - 以 DataFrame 的列作为 x 轴的图形
- cucumber - 增强 cucumber-jvm 日志记录消息
- javascript - 如何在 JavaScript 中 mouseup(鼠标释放)后调用函数?
- r - 李克特图:相同的脚本,但不同的结果
- node.js - 如何找到关于 service_id 的数据?