它是空的,因为data
无人居住。
Solution
- 删除所有编码
class Tabelle()
- Add
pass
into class Tabelle()
- 将以下内容添加到构造函数中,
__init__()
of class RV()
Snippets
self.data = [{'spalte1_SP': str(x['SP1']), 'spalte2_SP': str(x['SP2']), 'spalte3_SP': str(x['SP3'])} for x in items]
Kivy Recycle查看 » 数据
视图是通过处理生成的data,本质上是一个列表
字典,并使用这些字典生成视图类的实例
按要求。
data
当前视图适配器使用的数据。这是一个字典列表
其键映射到视图类的相应属性名称。
data 是一个 AliasProperty,用于获取和设置用于生成的数据
观点。
Example
main.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
from kivy.uix.boxlayout import BoxLayout
items = [{'SP1': 'Artikelnummer', 'SP2': 'Name', 'SP3': 'Groesse'},
{'SP1': '510001', 'SP2': 'Big Pump', 'SP3': '1.50 L'},
{'SP1': '523001', 'SP2': 'Leonie Still', 'SP3': '1.50 L'},
{'SP1': '641301', 'SP2': 'Cola Mix', 'SP3': '1.50 L'}
]
class Tabelle(BoxLayout):
pass
Builder.load_string('''
<Tabelle>:
orientation: 'horizontal'
spalte1_SP: 'spalte1'
spalte2_SP: 'spalte2'
spalte3_SP: 'spalte3'
Label:
id: SP1
text: root.spalte1_SP
Label:
id: SP2
text: root.spalte2_SP
Label:
id: SP3
text: root.spalte3_SP
<RV>:
viewclass: 'Tabelle'
RecycleBoxLayout:
default_size: None, dp(20)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
''')
class RV(RecycleView):
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
self.data = [{'spalte1_SP': str(x['SP1']), 'spalte2_SP': str(x['SP2']), 'spalte3_SP': str(x['SP3'])} for x in items]
class TestApp(App):
def build(self):
return RV()
if __name__ == '__main__':
TestApp().run()
Output
![Result](https://i.stack.imgur.com/ZEcsc.png)