日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Clouda API使用手冊之Router Model Collection

Router

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

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供安岳網(wǎng)站建設、安岳做網(wǎng)站、安岳網(wǎng)站設計、安岳網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、安岳企業(yè)網(wǎng)站模板建站服務,10余年安岳做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。

  • 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的數(shù)據(jù)模型。

 
 
  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

    字段的數(shù)據(jù)類型,包括一下數(shù)據(jù)類型:

類型意義
int整形
datetime日期
string字符串數(shù)
object對象
array數(shù)組
model數(shù)據(jù)模型
collection數(shù)據(jù)集合
  • 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位且必須為數(shù)字
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

        使用自定義函數(shù)對字段進行驗證

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

        該驗證函數(shù)在服務器端運行,先獲取指定modelObj的數(shù)據(jù),然后根據(jù)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)

    創(chuàng)建一個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數(shù)據(jù)對象

    newStudent.getData();
  • destroy

    語法:destroy()

    刪除model

    newStudent.destroy();
  • onValidation

    語法:onValidation(ispass, runat, validationResult)

    對Model驗證結果的監(jiān)聽方法

    • 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)

    創(chuàng)建一個Collection

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

    語法:size()

    獲取collection中包含Model的數(shù)量。

    session.studentCollection.size();
  • add

    語法:add(row)

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

    session.studentCollection.add(newStudent);
  • update

    語法:update(updateMap,where)

    更新collection中滿足條件的數(shù)據(jù)。

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

    語法:remove(where)

    將數(shù)據(jù)從collection中去除,但并不實際刪除。

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

    當沒有參數(shù)時,去除collection中所有數(shù)據(jù)。

  • destroy

    語法:destroy(where)

    將數(shù)據(jù)從collection中實際刪除。

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

    當沒有參數(shù)時,刪除collection中所有數(shù)據(jù)。

  • setData

    語法:setData(dataMap)

    使用dataMap對Model賦值

  • find

    語法:find(where)

    查詢Collection中符合條件的所有數(shù)據(jù)。

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

    當沒有參數(shù)時,返回所有的數(shù)據(jù)。

  • addSorters

    語法:addSorters()

    collection中添加排序方法

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

    collection按照"time"降序排序。

  • clearSorters

    語法:clearSorters()

    清空collection中排序方法

    session.studentCollection.clearSorters();
  • applyStorters

    語法:applyStorters()

    手動執(zhí)行所有的排序方法

    session.studentCollection.applyStorters();
  • get

    語法:get()

    根據(jù)下標取出對應的數(shù)據(jù)

    session.studentCollection.get(2);
  • toJSON

    語法:toJSON()

    返回一個JSON對象

    session.studentCollection.toJSON();
  • getData

    語法:getData()

    獲取包含所有數(shù)據(jù)的數(shù)組

    session.studentCollection.getData();
  • save

    語法:save()

    將collection的修改保存到Server。

    session.studentCollection.save();
  • pluck

    語法:pluck(key)

    返回Collection某一字段所有數(shù)據(jù)的數(shù)組

    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’數(shù)據(jù)的數(shù)組。

  • 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()

新聞名稱:Clouda API使用手冊之Router Model Collection
文章分享:http://www.dlmjj.cn/article/ccedipc.html