成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Clouda API使用手冊之Router Model Collection

移動開發 Android
Clouda是簡單,可依賴的實時Javascript框架。對一個想開發移動webapp的開發者來說,可以使用clouda開發框架,實現一個功能和體驗與native app齊平的輕應用。

Router

用于建立URL(其路徑部分)和Controller的對應關系,一個Controller可以對應多個URL,但是一個URL只能對應一個Controller。

  • add

    1. 語法:add({pattren:'', action:''}) 
    2.  
    3. 在router中添加一組pattren與Controller的對于關系 
    4.  
    5. sumeru.router.add( 
    6.     { 
    7.         pattern: '/studentList'
    8.         action: 'App.studentList' 
    9.     } 
    10. ); 

    • pattern

      URL(其路徑部分的值)

    • action

      對應Controller的名稱

    如果你想關閉Server渲染,可使用下面方法:

    1. sumeru.router.add( 
    2.     { 
    3.         pattern: '/studentList'
    4.         action: 'App.studentList' 
    5.         server_render:false 
    6.     } 
    • server_render

      Server渲染開關,false:關閉,默認為開啟

  • setDefault

    語法:setDefault(controllerName)

    設置默認啟動Controller

    sumeru.router.setDefault('App.studentList');
  • externalProcessor.add(processor);

    語法:sumeru.router.externalProcessor.add(processor);

    添加外部處理器

    添加一個backbone的外部處理器  sumeru.router.externalProcessor.add(Backbone.Router.extend());

#p#

Model

Model用來定義App的數據模型。

  1. Model.student = function(exports){ 
  2.     exports.config = { 
  3.         fields: [ 
  4.             {name : 'studentName', type: 'string'}, 
  5.             {name : 'age',         type: 'int'}, 
  6.             {name : 'gender',      type: 'string'
  7.         ] 
  8.     }; 
  9.  }; 
屬性
  • name

    字段的名稱

  • type

    字段的數據類型,包括一下數據類型:

類型 意義
int 整形
datetime 日期
string 字符串數
object 對象
array 數組
model 數據模型
collection 數據集合
  • relation

    使用relation時type屬性值必須為“model”。

    {name: 'class',  type: 'model', relation: 'one' , model:'Model.class'},
    • one

      引用一個Model

    • many

      引入一個Collection

  • defaultValue

    字段的默認值

    {name: 'gender',  type: 'string', defaultValue:'male'},
  • validation

    {name: 'name',  type: 'string', validation:'length[1,20]'},

    字段的驗證,validation包括以下方法:

方法 意義
length[min,max] 字段值的長度在min-max的范圍。
minlength(min) 字段值不小于min
maxlength(min) 字段值不大于min
required 字段值不能為空
unique 字段值必須唯一
telephone 字段值必須為電話號碼格式
mobilephone 字段值必須為手機號碼格式,長度為11位且必須為數字
email 字段值必須為email格式
onlyletter 字段值必須是字母
nospecialchars 字段值不能包含特殊字符
date 字段值必須是日期格式
url 字段值必須是URL
chinese 字段值必須是中文

注:多個驗證條件之間使用" | "連接

    {name: 'name',  type: 'string', validation:'length[1,20]|required'},
  • addRule

    除了上面的驗證方法外,還可以自定義驗證方法。

    1. sumeru.validation.addRule(ruleName,{ 
    2.                                 "runat" : "client"
    3.  
    4.                                 驗證方法  , 
    5.  
    6.                                 "msg"   : ""
    7.                                }); 
    • ruleName

      驗證方法的名稱,如"chinese"、"url"

    • runat

      定義在哪個端上(client/server)進行驗證

      • client

        在客戶端上進行驗證

      • server

        在服務器端進行驗證

      • both

        兩段都需要驗證

    • 驗證方法:該API中框架提供三種自定義驗證方法(三種方法(regxp/func/asyncFunc)每次只能使用一種

      • regxp

        使用自定義正則表達式對字段進行驗證

        1. sumeru.validation.addRule(ruleName,{ 
        2.                                        "runat" : "client"
        3.  
        4.                                        "regxp" : "()"
        5.  
        6.                                        "msg"   : ""
        7.                                }); 
      • func

        使用自定義函數對字段進行驗證

        1. sumeru.validation.addRule(ruleName,{ 
        2.                                          "runat" : "client"
        3.  
        4.                                          "func" : function(){}, 
        5.  
        6.                                          "msg"   : ""
        7.                                 }); 
      • asyncFunc

        該驗證函數在服務器端運行,先獲取指定modelObj的數據,然后根據asyncFunc中的方法進行驗證,在callback中給出驗證的結果。

        1. sumeru.validation.addRule(ruleName,{ 
        2.                                        "runat" : "client"
        3.  
        4.                                        "asyncFunc":function(callback,k,v,modelObj){} 
        5.  
        6.                                        "msg"   : ""
        7.                                }); 
    • msg

      驗證失敗后返回的信息

  • create

    語法:create(modelName)

    創建一個model

    var newStudent = sumeru.model.create('Model.student')
  • setter

    newStudent.studentName = 'John';        
  • set

    語法:set(key,value)

    設置Model中相應字段的值

    newStudent.set('studentName','John');
  • setData

    語法:setData(dataMap)

    使用dataMap對Model賦值

    1. newStudent.setData({'studnetName' : 'Smith'
    2.                             'age' : 19, 
    3.                          'gender' : 'male' 
    4.                   }); 
  • getter

    var name = newStudent.studentName;
  • get

    語法:get(key)

    獲取某一字段的值

    newStudent.get('studentName');
  • getId

    語法:getId()

    獲取model的唯一Id

    newStudent.getId();
  • getData

    語法:getData()

    返回一個JSON數據對象

    newStudent.getData();
  • destroy

    語法:destroy()

    刪除model

    newStudent.destroy();
  • onValidation

    語法:onValidation(ispass, runat, validationResult)

    對Model驗證結果的監聽方法

    • ispass

      驗證是否通過的標志

      • true

        驗證通過

      • false

        驗證不通過

    • runat

      返回進行驗證的端(客戶端或者服務器端)

      • client

        表示在客戶端進行驗證

      • server

        表示在服務器端進行驗證

    • validationResult

      驗證返回信息

      1. newStudent.onValidation = function(ispass, runat, validationResult){ 
      2.  
      3.     if(ispass){console.log("Validation success !");} 
      4.  
      5.     console.log((runat=='client'?'Client':'Server')+(ispass==true?'Validation Success!':'Validation failed!')); 
      6.  
      7.     for(var i = validationResult.length-1; i>=0; i--){ 
      8.         console.log(runat=='client'?'Client':'Server')+'result is:'+validationResult[i].msg); 
      9.     } 
      10. }; 

      詳細代碼和說明請參考《Examples》文檔。

#p#

Collection

Collection是Model的集合,我們之前曾使用過的subscribe()返回的結果集即是Collection。

  1. session.studentCollection = env.subscribe("pub-allStudents",function(myCollection){ 
  2.  
  3. }); 
  • create

    語法:create(dataMap)

    創建一個Collection

    1. sumeru.collection.create({'studnetName' : 'Smith'
    2.                                   'age' : 19, 
    3.                                'gender' : 'male' 
    4.                         }); 
  • size

    語法:size()

    獲取collection中包含Model的數量。

    session.studentCollection.size();
  • add

    語法:add(row)

    在collection中添加一行數據(每行數據實際是一個Model)。

    session.studentCollection.add(newStudent);
  • update

    語法:update(updateMap,where)

    更新collection中滿足條件的數據。

    session.studentCollection.update({'name':'Jack'},{'name':'John'});
  • remove

    語法:remove(where)

    將數據從collection中去除,但并不實際刪除。

    session.studentCollection.remove({'name':'John'});

    當沒有參數時,去除collection中所有數據。

  • destroy

    語法:destroy(where)

    將數據從collection中實際刪除。

    session.studentCollection.destroy({'name':'John'});

    當沒有參數時,刪除collection中所有數據。

  • setData

    語法:setData(dataMap)

    使用dataMap對Model賦值

  • find

    語法:find(where)

    查詢Collection中符合條件的所有數據。

    session.studentCollection.find({'name':'John'});

    當沒有參數時,返回所有的數據。

  • addSorters

    語法:addSorters()

    collection中添加排序方法

    session.studentCollection.addSorters('time','DESC')

    collection按照"time"降序排序。

  • clearSorters

    語法:clearSorters()

    清空collection中排序方法

    session.studentCollection.clearSorters();
  • applyStorters

    語法:applyStorters()

    手動執行所有的排序方法

    session.studentCollection.applyStorters();
  • get

    語法:get()

    根據下標取出對應的數據

    session.studentCollection.get(2);   
  • toJSON

    語法:toJSON()

    返回一個JSON對象

    session.studentCollection.toJSON();
  • getData

    語法:getData()

    獲取包含所有數據的數組

    session.studentCollection.getData();
  • save

    語法:save()

    將collection的修改保存到Server。

    session.studentCollection.save();
  • pluck

    語法:pluck(key)

    返回Collection某一字段所有數據的數組

    session.studentCollection.pluck('age');
  • hold

    語法:hold()

    暫停collection實時更新

    session.studentCollection.hold();   
  • releaseHold

    語法:releaseHold()

    恢復對collection的實時更新

    session.studentCollection.releaseHold();
  • where

    語法:where()

    在collection中指定查詢條件,需要與find、update、remove、destroy連用。

    1. session.studentCollection.where({'gender':'male'}); 
    2.  
    3. session.studentCollection.find(); 

    返回collection中‘gender’值為‘male’數據的數組。

  • orWhere

    語法:orWhere()

    在collection中添加一個“or”條件,需要與find、update、remove、destroy連用。

    1. session.studentCollection.orWhere({'gender':'male'}); 
    2.  
    3. session.studentCollection.find(); 
  • clearWheres

    語法:clearWheres()

    清空collection中所有查詢條件

    session.studentCollection.clearWheres()
責任編輯:張葉青
相關推薦

2013-10-31 14:55:22

2013-10-31 13:47:23

CloudaAPI

2013-10-31 14:30:44

CloudaAPI

2013-10-31 15:12:57

CloudaAPI

2010-05-20 19:12:37

2009-10-26 11:11:33

linux Emacs

2010-05-19 10:40:46

Subversion

2009-12-02 18:03:00

PHP cURL

2011-08-09 13:22:31

iPhoneSqlite數據庫

2010-08-31 08:59:06

marginHTML

2010-05-26 14:01:47

SVN安裝使用手冊

2010-05-21 12:37:49

SVN使用教程

2010-05-19 10:57:34

Subversion配

2010-05-26 12:59:48

SVN簡易使用手冊

2010-05-27 13:35:43

SVN簡易使用手冊

2010-06-07 12:38:37

Cacti使用手冊

2010-05-26 13:17:55

SVN簡易使用手冊

2010-05-26 13:51:40

SVN安裝使用手冊

2015-08-06 11:10:46

開源IaaS軟件ZStack本地存儲

2010-06-09 17:01:26

Cacti使用手冊
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 夜夜爽99久久国产综合精品女不卡 | 亚洲一区二区三区视频在线 | 日本精品视频在线 | 国产成人精品一区二区三 | 日本亚洲欧美 | 国产精品乱码一区二区三区 | 免费激情 | 国产精品中文字幕在线 | 日韩乱码在线 | 在线看日韩 | 成人在线小视频 | 国产精品影视 | 国产欧美性成人精品午夜 | 国产精品三级 | 日日夜夜精品免费视频 | 亚洲免费三区 | 国产一区二区高清在线 | 韩日在线视频 | 91久久久久久久 | 国产片淫级awww| 久久久久av | 在线免费观看成年人视频 | 久久一二 | www.久久久久久久久久久 | 亚洲视频在线播放 | 999久久久 | 欧美精品二区 | 久久久久久国产精品mv | 精品国产乱码久久久久久丨区2区 | 国产精品久久久久久久久久免费看 | 韩国精品在线观看 | 我要看黄色录像一级片 | 免费在线观看一区二区 | 日韩国产一区二区三区 | 亚洲国产高清高潮精品美女 | www.婷婷亚洲基地 | 少妇一区在线观看 | 中文字幕不卡在线观看 | 影音先锋中文字幕在线观看 | 国产精品美女久久久久aⅴ国产馆 | 五月婷婷 六月丁香 |