圖解AngularJS Wijmo5和LightSwitch

來源:互聯網
上載者:User

標籤:angularjs   wijmo 5   lightswitch   odata   linq   

??

Visual Studio 2013 中的 LightSwitch 有新增功能,包括更好的團隊開發支援以及在構建 HTML 用戶端案頭和 Office 365 應用程式方面的改進。本文結合最新發行的Wijmo 5提供的AngularJs進行圖解。

基於Visual Studio LightSwitch作為資料來源,我們使用Wijmo 5控制項快速的建立 AngularJS應用程式。

插入資料記錄

商務規則校正

資料記錄更新

選擇資料記錄,點擊鍵盤上刪除按鍵

點擊列頭,進行資料排序

並發性校正(由LightSwitch的後端提供)。

Wijmo 5控制項集

2014年10月7日---葡萄城宣布正式發布Wijmo 5。Wijmo 5不再相容傳統瀏覽器(<= IE9),純HTML5控制項集。並且,發布並Wijmo 5全部的控制項中將全面支援Angular JS。

為何使用Wijmo 5和LightSwitch?
  • 為了100%控制UI:LightSwitch HTML Client基於JQuery Mobile,這導致為了控制UI不得不花費大量時間。
  • 為了實現安全性:安全性原則一般在Server端實現。無法通過AngularJs前端技術實現。LightSwitch使得安全性非常容易實現。
  • 為了處理並發性:當多人同時更新DB會導致並發性,所幸,LightSwitch已經自動實現該特性。
  • 為了用LightSwitch進行管理介面代碼:基於LightSwitch,我們無需用AngularJs實現管理介面代碼,LightSwitch已經實現了,故結合LightSwitch和AngularJs使得編程非常容易。
  • 為了加快開發:當前使用LightSwitch,可以大大減少代碼編寫,這意味著開發進程會加速,bug會減少。

 

例子如下所示:

 

LightSwitch 業務層

在解決方案視圖,在資料來源DataSources右鍵,選擇Add Table

建立ToDo表

點擊寫代碼按鈕,選擇Validate方法,在產生的模板中,插入驗證代碼。

partial void ToDoes_Validate(ToDo entity, EntitySetValidationResultsBuilder results)        {            // Do not allow a task to be called {New Task]            if (entity.TaskName == "[New Task]")            {                results.AddEntityError(                    "Task cannot be named [New Task]"                    );            }            // Do not allow more than 1 incomplete Task            if (entity.IsComplete == false)            {                int intCountOfIncomplete =                    this.DataWorkspace.ApplicationData.ToDoes                    .Where(x => x.IsComplete == false)                    .Where(x => x.Id != entity.Id).Count();                if (intCountOfIncomplete > 0)                {                    results.AddEntityError(                        "Cannot have more than 1 incomplete Task"                        );                }            }        }
Wijmo 5代碼

Wijmo 5:輸入郵箱即可獲得下載URL地址

 

解壓Wijmo範例,定位到“..\Samples\JS\Angular\OData”目錄,拷貝Vendor和styles檔案夾到LightSwitch Server工程的Scripts檔案夾。

建立wijmo.data檔案夾,下載ODataCollectionView.js,並拷貝在wijmo.data檔案夾下。

AngularJs代碼

在scripts檔案夾下建立app.js指令檔,並輸入如下代碼。

// 在AngularJS 聲明依賴 Wijmo "wj" module:var app = angular.module(‘app‘, [‘wj‘]);
在scripts檔案夾下建立controllers檔案夾,並建立appCtrl.js,並輸入如下代碼。
‘use strict‘;var app = angular.module(‘app‘);app.controller(‘appToDoCtrl‘, function appToDoCtrl($scope) {    // define data service URL and data types for specific columns    var oDataService = ‘/ApplicationData.svc‘, dataTypes = [];    // load ToDos table    $scope.cvToDo = new wijmo.data.ODataCollectionView(        { serviceUrl: oDataService, entityName: ‘ToDoes‘ },        [‘Id‘],        {            serverSettings: {                selects: [‘Id‘, ‘RowVersion‘, ‘TaskName‘,                    ‘IsComplete‘, ‘Created‘, ‘Modified‘]            }        },        dataTypes, loaded, true);    // Display any errors    $scope.cvToDo.error.addHandler(function (sender, args) {        alert(sender.errorMsg);    });    // tell scope when tables finish loading    function loaded() {        $scope.$apply();    }});
建立HTML頁面

建立ToDo.htm頁面,並輸入如下代碼:

<!DOCTYPE html><html lang="en" ng-app="app" ng-controller="appToDoCtrl"><head>    <meta charset="utf-8" />    <title>To DO</title>    <!-- ensure IE uses the latest version of IE (yes, yes...) -->    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />    <meta name="viewport" content="width=device-width, initial-scale=1.0" />    <!-- jQuery/Angular/Bootstrap -->    <script src="http://code.jquery.com/jquery-2.0.0.min.js"             type="text/javascript"></script>    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"             type="text/javascript"></script>    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular-route.min.js"             type="text/javascript"></script>    <script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"             type="text/javascript"></script>    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"           type="text/css" />    <!-- Wijmo -->    <script src="scripts/vendor/wijmo.min.js" type="text/javascript"></script>    <script src="scripts/vendor/wijmo.input.min.js" type="text/javascript"></script>    <script src="scripts/vendor/wijmo.grid.min.js" type="text/javascript"></script>    <link href="styles/vendor/wijmo.min.css" rel="stylesheet" />    <!-- app scripts -->    <script src="scripts/wijmo.data/ODataCollectionView.js" type="text/javascript"></script>    <script src="scripts/app.js" type="text/javascript"></script>    <script src="scripts/controllers/appCtrl.js" type="text/javascript"></script>    <!-- Wijmo-Angular interop -->    <script src="scripts/vendor/wijmo.angular.min.js" type="text/javascript"></script>    <!-- app styles -->    <link href="styles/app.css" rel="stylesheet" type="text/css" /></head><body>    <div class="header">        <div class="container" style="position:relative">            <h1>                TO DO Example            </h1>        </div>    </div></body></html>
 

在<body>內添加Wijmo Grid代碼:

<div class="container">        <wj-flex-grid class="grid"                       allow-add-new="true"                       allow-delete="true"                       items-source="cvToDo">            <wj-flex-grid-column                                  binding="TaskName"                                  width="300"                                  header="Task Name">            </wj-flex-grid-column>            <wj-flex-grid-column                                  binding="IsComplete"                                  datatype="Boolean"                                  width="200"                                  header="IsComplete">            </wj-flex-grid-column>        </wj-flex-grid>    </div>
 參考文章:
  • Microsoft Visual Studio LightSwitch 介紹
  • LightSwitch開發人員中心
  • LightSwitch 團隊部落格
  • Wijmo5 中文部落格

圖解AngularJS Wijmo5和LightSwitch

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.