走進PIMShell(5)–Form(表單)的應用

來源:互聯網
上載者:User

在pimshell中實現一個網頁建議採用htm/xml/js三個檔案。.htm檔案定義介面中的DOM元素,.xml檔案為DOM元素附加所需要的行為(behavior),.js檔案實現javascript代碼。但是在實際應用時,需要將這些檔案放入到某個外掛程式(可以是自製的外掛程式)的目錄中才能正常運行。為了方便網頁的編寫和運行,PIMShell提供了一個特製的Form(表單)外掛程式。一個Form可代表一個網頁,也由htm/xml/javascript三部分組成。所不同的是,Form的內容都儲存在PIMShell的資料檔案中。這樣,Form的編輯和執行唾手可得,而且Form可以像其他類型的資料一樣匯入匯出,與他人分享。

這與Access中的Form是不是有些類似呢?由於PIMShell中的Form是網頁的形式,所以相對Access中的Form而言,設計更靈活。每個Form可以實現一個應用,多個Form可以組成一個更複雜的應用。還可以為Form設定表徵圖,從而方便標識。

在PIMShell的官方網站上還提供了一個Form Gallery(表單庫):http://www.pimshell.com/pimshell/go.asp?LinkId=7,從而方便Form的共用與交流。

我們仍以使用者列表為例,看看在Form中是如何?的。

 

1、Form的編輯介面

 

2、htm部分

  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <title>使用者列表</title>
  4. <link type="text/css" rel="Stylesheet" href="/css/main.css" />
  5. <xml src="do.bin?ItemId={E143F7B8-3088-4DD8-8DBD-AF6114B73B0A}&type=xml"></xml>
  6. <script type="text/javascript" src="do.bin?ItemId={E143F7B8-3088-4DD8-8DBD-AF6114B73B0A}&type=js" language="javascript"></script>
  7. </head>
  8. <body>
  9. <div id="List1"></div>
  10. </body>
  11. </html>
  • 行4:定義了頁面的樣式。在main.css檔案中為body設定了如下的樣式

    1. body
    2. {
    3.  behavior:url(#default#PIMShell);
    4. }

    這個樣式為body元素添加了一個名叫PIMShell的預設行為。這個行為負責解析後續的xml檔案,並激發onpageload事件,從而執行js檔案中的代碼。

  • 行5:定義xml部分,為頁面中的DOM元素附加行為。

  • 行6:定義js部分,包含需要的javascript代碼。

  • 行9:定義了一個名為List1的div元素,用於顯示列表資訊。

  •  

    3、xml部分

      1. <?xml version="1.0" encoding="utf-16"?>
      2. <page>
      3.     <root enableFrame="false" enableContextMenu="false">
      4.         <controls>
      5.             <control id="List1">
      6.                 <behaviors>
      7.                     <ListView autoFitRows="false" allowPage="false">
      8.                         <header>
      9.                             <cols>
      10.                                 <col name="name" text="姓名" width="60">
      11.                                     <bind>
      12.                                         <text>[#Name#]</text>
      13.                                     </bind>
      14.                                 </col>
      15.                                 <col name="sex" text="性別" width="40">
      16.                                     <bind>
      17.                                         <text>[#Sex#]</text>
      18.                                     </bind>
      19.                                 </col>
      20.                                 <col name="email" text="電子郵件" width="80">
      21.                                     <bind>
      22.                                         <a href="mailto:[*Email*]"><img src="pim://images/mailsend.ico" border="0" /></a>
      23.                                     </bind>
      24.                                 </col>
      25.                             </cols>
      26.                         </header>
      27.                     </ListView>
      28.                 </behaviors>
      29.             </control>
      30.         </controls>
      31.         <events>
      32.             <onpageload handler="onpageload" />
      33.         </events>
      34.     </root>
      35. </page>
    • 行5:將元素List1定義為組件
    • 行7:為List1附加行為ListView
    • 行8-26:定義列表中用到的屬性列
    • 行32:綁定事件onpageload

    4、javascript部分

      1. //事件:onpageload
      2. function onpageload()
      3. {
      4.     //準備記錄集
      5.     var oEntityset=__prepareEntityset();
      6.     
      7.     //綁定
      8.     $("List1").dataSource=oEntityset;
      9.     $("List1").dataBind();
      10. }
      11. //準備記錄集
      12. var g_sUsers="張三,男,zhangsan@msn.com;李四,男,lisi@msn.com;王霞,女,wangxia@msn.com";
      13. function __prepareEntityset()
      14. {
      15.     //
      16.     var oEntityset=Sys.Entityset;
      17.     
      18.     //
      19.     var oUserArray=g_sUsers.split(";");
      20.     for(var i=0;i<oUserArray.length;i++)
      21.     {
      22.         //添加一條新記錄
      23.         oEntityset.addNew();
      24.         
      25.         //
      26.         var oPropArray=oUserArray[i].split(",");
      27.         
      28.         oEntityset("Name")=oPropArray[0];
      29.         oEntityset("Sex")=oPropArray[1];
      30.         oEntityset("Email")=oPropArray[2];
      31.     }
      32.     
      33.     //移到首部
      34.     oEntityset.movefirst();
      35.     
      36.     return oEntityset;
      37. }
    • 行2:響應事件onpageload
    • 行5:構造一個測試用的記錄集oEntityset
    • 行8-9:將記錄集oEntityset綁定到元素List1上,從而自動完成清單的顯示

    5、網頁運行效果

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.