Use static members to implement server cache (navigation breadcrumb )~ Continued

Source: Internet
Author: User

返回目录

在写完首篇cache文章后,有些朋友给我来信,希望可以使用JS的方法来实现这个导航功能,所以,才有了这篇文章,JS与C#不同,它虽然有引用类型,但它不具备一些引用类型的特性,如它的方法参数为对象时,也是通过值传递的,而不是通过内存地址,而在进行导航制作时,我们正是使用了引用类型的这个特性,所以,我们的JS方法,就不能和C#相同了,如果使用其它方式,如,使用名称保存在一个变量里。

下面是JS方式实现的导航,希望对JS朋友有些帮助

<script type="text/javascript">        //对象实体        var BannerModel = function (name, url, id, parentID) {            return {                Name: name,                Url: url,                ID: id,                ParentID: parentID,                Parent: {}            };        }        var BannerStr = "";        var Data = [new BannerModel("首页", "/", 1, 0), new BannerModel("用户中心", "/UserInfo", 2, 1), new BannerModel("基本信息设置", "/UserInfoSet", 3, 2)];        //找老祖宗...
    function GetParent(o) { if (o != undefined && o.ID != undefined) { BannerStr = "<a href=" + o.Url + ">" + o.Name + "</a>" + ">" + BannerStr; for (var i in Data) { if (Data[i].ID == o.ParentID) { o.Parent = Data[i]; break; } } GetParent(o.Parent); } } //导航工厂
var BannerFactory = { GetTreeBanner: function (url) { var temp = ""; BannerStr = ""; for (var i in Data) { if (Data[i].Url == url) { temp = Data[i]; break; } } GetParent(temp); return BannerStr; } } document.write(BannerFactory.GetTreeBanner("/UserInfoSet")); </script>

看JS生成的导航

返回目录

使用static静态成员实现服务器端缓存(导航面包屑)~续

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.