绑定到AliasProperty时会发生什么?

时间:2016-04-28 17:41:40

标签: python events kivy

这是我的简化代码:

class Player(Widget):
    _health = NumericProperty(100)

    def _get_health(self):
        return self._health

    health = AliasProperty(_get_health, bind=['_health'])

我这样做是为了health' readonly'。

奇怪的是,当我删除bind=['_health']时它不起作用。

所以我的问题是:bind=['_health']实际上做了什么?我理解AliasProperty允许我定义一个getter和可选的setter,它在访问属性时运行(类似于Python' s @property)。

那么在这种情况下bind=['_health']是什么,以及当我排除它时,为什么该属性不起作用(不反映基础_health的状态)?

1 个答案:

答案 0 :(得分:1)

public function store(Request $request) { $request->user_id = Auth::user()->id; //assigning user_id value to the current logged in user's id (this has to be before adding the request to the inputs variable so when you execute ::Create($inputs) it will be there) $inputs = $request->all(); $product = Product::Create($inputs); return redirect()->action('ProductController@index'); } 参数告诉属性引擎哪些其他属性要监视更改,因为它们与正在考虑的bind相关。

让我们从文档中获取(简化)示例:

AliasProperty

此处,def get_right(self): return self.x + self.width right = AliasProperty(get_right, bind=['x', 'width']) 依赖于其他两个属性。如果我们只编写了right,则只有bind=['x']的更改才会导致x触发更改事件,而right的更改将被忽略(但是,如果之后更改为width更改为width时,将触发具有预期值的事件,如果手动检索该值,则也将更正。)

相关问题