MVVM Pattern"

From Documentation
m (correct highlight (via JWB))
 
Line 5: Line 5:
  
 
= Get Charts =
 
= Get Charts =
Get a <tt>Charts</tt> by <tt>wireComponents()</tt>, please refer to [http://books.zkoss.org/zk-mvvm-book/8.0/advanced/wire_components.html MVVM Reference / Wire Components]
+
Get a <code>Charts</code> by <code>wireComponents()</code>, please refer to [http://books.zkoss.org/zk-mvvm-book/8.0/advanced/wire_components.html MVVM Reference / Wire Components]
  
<source lang='java' high='8'>
+
<source lang='java' highlight='8'>
 
public class ShiftViewModel {
 
public class ShiftViewModel {
 
     @Wire
 
     @Wire
Line 25: Line 25:
  
 
= Get ChartsEvent =
 
= Get ChartsEvent =
Because you usually need <tt>ChartsEvent</tt> API, you can get it by <tt>@ContextParam</tt> like:
+
Because you usually need <code>ChartsEvent</code> API, you can get it by <code>@ContextParam</code> like:
  
<source lang='java' high='2'>
+
<source lang='java' highlight='2'>
 
     @Command
 
     @Command
 
     public void shiftPoint(@ContextParam(ContextType.TRIGGER_EVENT) ChartsEvent event) {
 
     public void shiftPoint(@ContextParam(ContextType.TRIGGER_EVENT) ChartsEvent event) {

Latest revision as of 03:09, 18 January 2022


You still can work with Charts in MVVM pattern with some exceptional usages.

Get Charts

Get a Charts by wireComponents(), please refer to MVVM Reference / Wire Components

public class ShiftViewModel {
    @Wire
    Charts chart;

    //http://books.zkoss.org/zk-mvvm-book/8.0/advanced/wire_components.html
    @AfterCompose
    public void doAfterCompose(@ContextParam(ContextType.VIEW) Component view) throws Exception {
        Selectors.wireComponents(view, this, false);
        // initial series data
        initPoints();
        // hide some unnecessary options
        hideOptions();
    }
...

Get ChartsEvent

Because you usually need ChartsEvent API, you can get it by @ContextParam like:

    @Command
    public void shiftPoint(@ContextParam(ContextType.TRIGGER_EVENT) ChartsEvent event) {
        // retrieve the point object.
        Point point = event.getPoint();
        // shift the point by updating its x value.
        point.setX(point.getX().intValue() + random() / 10);
    }


< Get Complete Source Code of This Book >


Last Update : 2022/01/18

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.