Binding in Special Attribute

From Documentation
< User:Hawk
Revision as of 02:27, 14 March 2013 by Hawk (talk | contribs)

location:

  • MVVM/Advanced/Parameter
  • MVVM/Advanced/Binding in Special Attributes


When a ViewModel's property changes, ZK will re-load those corresponding bindings on attributes. Then this reloading usually causes a UI change because attributes control a component's status and behavior. This is the basic way we change an attribute's value in MVVM approach. But there are some special attributes that we can't do so. ZK will not reload value of these special attributes after a component is created and their value is determined and fixed at creation phase. Therefore, we should bind these special attributes to those properties that will not change after component creation (or uses these attributes in the condition that don't care the changed properties).


Assume that an user's permission is unchanged when he visits the page and only the user with "admin" permission can see the "Delete" button. Then we can write a binding on if as follows:

	<!-- "if" usage  -->
	<button label="Edit" />	
	<button label="Delete" if="@load(vm.currentUser.admin)"/>

On the page above, those users without "admin" permission can't see the "Delete" button. Even if you assign the user with "admin" permission through a command, the "Delete" will not appear. But if you visit the page again after assigning the user "admin" permission, the button will appear.