-
constructor()
- The view-model's constructor is called first. - created(owningView: View, myView: View)
3.bind(bindingContext: Object, overrideContext: Object)
If the view-model has a
bind
callback, it will be invoked at this time.
The "binding context" to which the component is being bound will be passed first.
An "override context" will be passed second. 4.
attached()
- Next, the component is attached to the DOM (in document).
If the view-model has an attached
callback, it will be invoked at this time
组件添加到DOM上
5.detached() At some point in the future, the component may be removed from the DOM. If/When this happens, and if the view-model has a
detached
callback, this is when it will be invoked.
如果组件被从DOM上移出且组件有这个方法,那么这个方法将被调用。
6.unbind() - After a component is detached, it's usually unbound. If your view-model has the
unbind
callback, it will be invoked during this process.
detached()方法后才是unbind()方法。先分离后取消绑定。
unbind会直接开始改变view,detached肯定在unbind前面,首先要从DOM上面移出。
Each of these callbacks is optional.
这些回调都是可选的。 if you implement
bind
you will need to implement unbind
.
The same goes for attached
and detached
, but again, it isn't mandatory.通常。bind和unbind(), attached和detached方法是一对写入,但不是强制。
It is important to note that if you implement the
bind
callback function,
then the property changed callbacks for any bindable
properties will not be called when the property value is initially set.
The changed callback will be called for any subsequent time the bound value changes.意思是初始化的时候属性被初始化不会调用绑定的回调函数,只有在后面的时候属性改变才会调用回调。