您的位置:首页 > 其它

Dojo加载自定义对象

2016-04-11 13:09 387 查看
Dojo加载自定义对象的一种方法

定义有如下对象:

./js/com/WebGIS/Graphics/Shape.js中:

define(['dojo/_base/declare'], function (declare) {

    return declare(

        null,

        {

            color: 0,

            setColor: function (color) {

                this.color = color;

            }

        });

});

./js/com/WebGIS/Graphics/Circle.js中:

define(["dojo/_base/declare", "com/WebGIS/Graphics/Shape"], function (declare, Shape) {

    return declare(

        Shape,

        {

            constructor: function (radius) {

                this.radius = radius | this.setRadius;

            },

            setRadius: function (radius) {

                this.radius = radius;

            },

            area: function () {

                return Math.PI * this.radius * this.radius;

            }

        });

});

加载文件时:

    <script src="http://localhost:8080/dojoroot/dojo/dojo.js"></script>    //加载dojo

    <script>

        (function () {    

            var currentPath = location.href.substring(0, location.href.lastIndexOf("\/"));

            require({     //定义加载当前块环境需要的包名称定义

                packages: [{ name: "com", location: currentPath + "/js/com" }]

            })

            require(["com/WebGIS/Graphics/Circle", "dojo/domReady!"], function (Circle) {

                var circle = new Circle(4);

                console.log(circle.area());

                console.log(circle.color);

            });

        }());

    </script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: