8.1 viewmodel意义的体现与filter函数的巧妙应用
class BookViewModel:
def __init__(self, book):
self.title = book['title'],
self.publisher = book['publisher'],
self.pages = book['pages'],
self.author = '、'.join(book['author']),
self.price = book['price'],
self.summary = book['summary'],
self.image = book['image']
# @property注解可以让我们把一个方法当做一个属性来使用
@property
def intro(self):
intros = filter(lambda x: True if x else False,
[self.author[0], self.publisher[0], self.price[0]])
return ' / '.join(intros)Last updated
Was this helpful?