Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Controller(object):
- def __init__(self, task):
- self.task = task
- self.value = 5
- def onChange(self, value):
- self.value = value
- self.task(value)
- class View(object):
- def __init__(self, data):
- self.data = data
- self.shown = self.data
- self.controller = Controller(self.filterByColor) #
- # ^ controllernya, di inisialisasi sama function yang perlu dikerjain controller
- def filterByColor(self, value):
- self.shown = [x for x in self.data if x["color"] == value]
- self.render()
- def render(self):
- # anggep aja, ngerender view ulang
- pass
- def main():
- data = [
- {'color': 'red', 'student': 'budi'},
- {'color': 'green', 'student': 'joko'},
- {'color': 'blue', 'student': 'ani'},
- {'color': 'green', 'student': 'hamdi'}
- ]
- view = View(data)
- controller = view.controller
- print view.shown
- [{'color': 'red', 'student': 'budi'}, {'color': 'green', 'student': 'joko'}, {'color': 'blue', 'student': 'ani'}, {'color': 'green', 'student': 'hamdi'}]
- controller.onChange(value="green")
- print view.shown
- [{'color': 'green', 'student': 'joko'}, {'color': 'green', 'student': 'hamdi'}]
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement