Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – Creating a computer view


Now, let's create a simple view for Computer. It will be named computerList.views.ComputerView :

package computerList.views;

import computerList.models.Computer;
import js.Dom;
import js.Lib;

class ComputerView
{
   var computer:Computer;
   public var mainNode:js.HtmlDom;
   
   //To let the parent view know when we delete our object
   public var on Delete:ComputerView -> Void;
   
   public function new(comp:Computer)
   {
      computer = comp;
      mainNode = Lib.document.createElement("tr");
      var nameCell = Lib.document.createElement("td");
      nameCell.appendChild(Lib.document.createTextNode(computer.name));
      var osCell = Lib.document.createElement("td");
      var detailsCell = Lib.document.createElement("td");
      osCell.appendChild(Lib.document.createTextNode)
            switch(computer.operatingSystem)
            {
               case Linux(distro):
                  detailsCell.appendChild(Lib.document.createTextNode...