Hi the following code was taken from chapter 34 section 10.2
I modified the view container for "all phone numbers" to be a class
and the datapath's xpath to be set via an attribute from that class.
Now the delete button although it does say the node is deleted does
not actually remove the view.
If the xpath (in the class) is set directly to
"phonebook:/contacts/contact" this works fine.
Any ideas ? My work around was to create an instance of the datapath
in the oninit event of "allv" (Checking first to see if the instance
is a clone) But if this is an error it should be fixed...


<canvas height="300" debug="true">
 <dataset name="phonebook" src="resources/phonebook.xml"/>

 <simplelayout axis="y" spacing="3"/>
 <view>
   <view name="newContact" datapath="new:/contact">
     <text>First Name:</text>
     <edittext name="firstName" datapath="@firstName" x="80"/>
     <text y="25">Last Name:</text>
     <edittext name="lastname" datapath="@lastName" x="80" y="25"/>
     <text y="50">Phone:</text>
     <edittext name="phone" datapath="@phone" x="80" y="50"/>
     <text y="75">Email:</text>
     <edittext name="email" datapath="@email" x="80" y="75"/>
     <button width="80" x="200">Add
       <handler name="onclick">
         parent.datapath.updateData();
         var dp= phonebook.getPointer();
         dp.selectChild();
         dp.addNodeFromPointer(parent.datapath);
         parent.setDatapath("new:/contact");
       </handler>
     </button>
   </view>
 </view>
 <button text="Delete selected">
   <handler name="onclick"><![CDATA[
Debug.write(all.nodes.length,all.clones[0])
Debug.write(all.clones[0].datapath.deleteNode())
//      for (var c = 0; c < all.nodes.length; ++c)
//        with (all.clones[c]) {
//          if (datapath.xpathQuery('@checked') == true)  {
//            datapath.deleteNode()
//            c--
//          }
//        }
]]>
   </handler>
 </button>

 <class name="allv">
   <attribute name="myPath" type="string" value="false"/>
   <datapath xpath="${parent.myPath}" pooling="true"/>
   <view>
     <simplelayout axis="x"/>
     <checkbox width="30" datapath="@checked">
       <handler name="onvalue">
         datapath.updateData()
       </handler>
       <method name="updateData">
         return this.value
       </method>
       <method name="applyData" args="d">
         setValue(d)
       </method>
     </checkbox>
     <text datapath="@firstName"/>
     <text datapath="@lastName"/>
     <text datapath="@phone"/>
     <text datapath="@email"/>
   </view>
 </class>
 <allv name="all" myPath="phonebook:/contacts/contact"/>
</canvas>

Reply via email to