在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ HTML/ 單頁(yè)面應(yīng)用(二) Router 類
準(zhǔn)備
Kendo UI 特效概述
Kendo MVVM 數(shù)據(jù)綁定(三) Click
Kendo MVVM 數(shù)據(jù)綁定(十) Source
Kendo MVVM 數(shù)據(jù)綁定(二) Checked
Kendo MVVM 數(shù)據(jù)綁定(五) Events
UI Widgets 概述
Kendo MVVM 數(shù)據(jù)綁定(一) attr
單頁(yè)面應(yīng)用(二) Router 類
單頁(yè)面應(yīng)用(四) Layout
Kendo DataSource 概述
Kendo MVVM 數(shù)據(jù)綁定(四) Disabled/Enabled
Kendo MVVM 數(shù)據(jù)綁定(十一) Value
Kendo MVVM (二) ObservableObject 對(duì)象
單頁(yè)面應(yīng)用(一)概述
Kendo UI 模板概述
Kendo MVVM 數(shù)據(jù)綁定(七) Invisible/Visible
Kendo MVVM 數(shù)據(jù)綁定(八) Style
初始化 Data 屬性
Kendo UI Validator 概述
單頁(yè)面應(yīng)用(三) View
Kendo MVVM 數(shù)據(jù)綁定(九) Text
Kendo MVVM (一) 概述
移動(dòng)應(yīng)用開發(fā)簡(jiǎn)介
Kendo MVVM 數(shù)據(jù)綁定(六) Html
使用 Kendo UI 庫(kù)實(shí)現(xiàn)對(duì)象的繼承

單頁(yè)面應(yīng)用(二) Router 類

Route 類負(fù)責(zé)跟蹤應(yīng)用的當(dāng)前狀態(tài)和支持在應(yīng)用的不同狀態(tài)之間切換。Route 通過(guò) Url 的片段功能(#url)和流量器的瀏覽歷史功能融合在一起。從而可以支持把應(yīng)用的某個(gè)狀態(tài)作為書簽添加到瀏覽器中。Route 也支持通過(guò)代碼在應(yīng)用的不同狀態(tài)之間切換。

Router 根路徑回調(diào)函數(shù)


<script>
    var router = new kendo.Router();

    router.route("/", function() {
        console.log("/ url was loaded");
    });

    $(function() {
        router.start();
    });
</script>

缺省情況下,如果 URL fragment 為空,將使用缺省的“/”的根路徑,此時(shí)對(duì)于的回調(diào)函數(shù)被調(diào)用,不管初始 URL 是什么,這個(gè)初始化的回調(diào)函數(shù)總會(huì)調(diào)用。 如果使用 IE,按 F12 可以打開 Developer Window,選擇 Console 可以看到 console.log 的打印信息。

http://wiki.jikexueyuan.com/project/kendo-ui-development-tutorial/images/35.jpg" alt="" />

參數(shù)

Router 支持 bound parameters, optional segments, 和 route globbing,類似于綁定參數(shù),可選參數(shù),匹配符匹配參數(shù)等。 例如:綁定參數(shù)


<script>
    var router = new kendo.Router();

    router.route("/items/:category/:id", function(category, id) {
        console.log(category, "item with", id, " was requested");
    });

    $(function() {
        router.start();

        // ...

        router.navigate("/items/books/59");
    });
</script>

當(dāng)運(yùn)行這個(gè)頁(yè)面時(shí),注意地址欄中的地址為:

<http://localhost:53223/Index.html#/items/books/59 –> #/items/books/59>

http://wiki.jikexueyuan.com/project/kendo-ui-development-tutorial/images/36.jpg" alt="" />

可選參數(shù)

如果 URL 的部分參數(shù)為可選的,此時(shí) Route 的規(guī)則為使用”()”,將可選參數(shù)放在括號(hào)內(nèi)。


<script>
    var router = new kendo.Router();

    router.route("/items(/:category)(/:id)", function(category, id) {
        console.log(category, "item with", id, " was requested");
    });

    $(function() {
        router.start();

        // ...
        router.navigate("/items/books/59");

        // ...
        router.navigate("/items");

        // ...
        router.navigate("/items/books");
    });
</script>

http://wiki.jikexueyuan.com/project/kendo-ui-development-tutorial/images/37.jpg" alt="" />

使用×通配符匹配參數(shù)


<script>
    var router = new kendo.Router();

    router.route("/items/*suffix", function(suffix) {
        console.log(suffix);
    });

    $(function() {
        router.start();

        // ...
        router.navigate("/items/books/59");

        // ...
        router.navigate("/items/accessories");

        // ...
        router.navigate("/items/books");
    });
</script>

http://wiki.jikexueyuan.com/project/kendo-ui-development-tutorial/images/38.jpg" alt="" />

頁(yè)面切換

navigation 方法可以用來(lái)切換應(yīng)用,對(duì)應(yīng)的路徑的回調(diào)方法被調(diào)用, navigation 方法修改 URL 的 fragment 部分(#后面部分)。 比如:


<a href="#/foo">Foo</a>

<script>
    var router = new kendo.Router();

    router.route("/foo", function() {
        console.log("welcome to foo");
    });

    $(function() {
        router.start();
        router.navigate("/foo");
    });
</script>

這個(gè)例子,將在地址欄顯示 http://xxx/index.html#/foo。 如果對(duì)應(yīng)的路徑不存在,Router 類觸發(fā) routeMissing 事件,并把 URL 作為參數(shù)傳入。

<script>
var router = new kendo.Router({ routeMissing: function(e) { console.log(e.url) } });

$(function() {
    router.start();
    router.navigate("/foo");
});
</script>

你可以通過(guò) change 事件來(lái)截獲這種頁(yè)面之間的切換,然后調(diào)用 preventDefault 阻止頁(yè)面切換。


<script>
var router = new kendo.Router({
    change: function(e) {
        console.log(url);
        e.preventDefault();
    }
});

$(function() {
    router.start();
    router.navigate("/foo");
});
</script>