当我选择可扩展树,然后在AngularJS中显示右侧静态html页面 [英] when I selected Expandable tree then Right side Static html page display in AngularJS

查看:67
本文介绍了当我选择可扩展树,然后在AngularJS中显示右侧静态html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我选择Expandable树然后在AngularJS中显示右侧静态html页面

------------------------- -------------------------------------------------- -----------



when I selected Expandable tree then Right side Static html page display in AngularJS
--------------------------------------------------------------------------------------

<script>
        var appBo = angular.module('appBo', []);
        appBo.directive('tree', function() {
          return {
            restrict: 'E',
            replace: true, 
            scope: {
              t: '=src' 
            },
            template: '<ul><branch ng-repeat="c in t.children" src="c"></branch></ul>'
          };
        })

        appBo.directive('branch', function($compile) {
          return {
            restrict: 'E',     
            replace: true, 
            scope: {
              b: '=src'.
            },
            template: '<li><a>{{ b.name }}</a></li>',
            link: function(scope, element, attrs) 
            var has_children = angular.isArray(scope.b.children);

              if (has_children) {
                element.append('<tree src="b"></tree>');

                $compile(element.contents())(scope);
              }

              //// Bind events
              element.on('click', function(event) {
                  event.stopPropagation();

                  if (has_children) {
                    element.toggleClass('collapsed');
                  }
              });
            }
          };
        })

        appBo.controller(TreelistController, function ($scope) {

          $scope.categories = {
            children: [
              {
                name: "Item A",
                children: [
                  {
                    name: "Item A-1",
                    children: [
                      {
                        name: "Item A-1-1"
                      },
                      {
                        name: "Item A-1-2"
                      }
                    ]
                  },
                  {
                    name: "Item A-2"
                  },
                      {
                        name: "Item A-3"
                      }
                ]
              },
            ]
          };
        });
    </script>

推荐答案

compile){
return {
restrict:'E',
replace :true,
范围:{
b:'= src'。
},
模板:'< li > < a > {{b.name}} < / a > < / li > ',
link:function(scope,element,attrs)
var has_children = angular.isArray(scope.b.children);

if(has_children){
element.append('< tree src = b > < / tree > ');
compile) { return { restrict: 'E', replace: true, scope: { b: '=src'. }, template: '<li><a>{{ b.name }}</a></li>', link: function(scope, element, attrs) var has_children = angular.isArray(scope.b.children); if (has_children) { element.append('<tree src="b"></tree>');


compile(element.contents()) (范围);
}

////绑定事件
element.on('click',function(event){
event.stopPropagation();

if(has_children){
element.toggleClass('collapsed');
}
});
}
};
})

appBo.controller(TreelistController,函数(
compile(element.contents())(scope); } //// Bind events element.on('click', function(event) { event.stopPropagation(); if (has_children) { element.toggleClass('collapsed'); } }); } }; }) appBo.controller(TreelistController, function (


scope){


这篇关于当我选择可扩展树,然后在AngularJS中显示右侧静态html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆