本文介绍了如何在$ http中为Angularjs重写json数组..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<html>
|<head>
<link rel="stylesheet" type="text/css" href="ajs.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script>
var myApp = angular.module('myApp', ['angularTreeview']);
myApp.controller('myController', function($scope){
//Tree model 1
$scope.roleList1 = [
{ "roleName" : "User", "roleId" : "role1", "children" : [
{ "roleName" : "subUser1", "roleId" : "role11", "children" : [] },
{ "roleName" : "subUser2", "roleId" : "role12", "children" : [
{ "roleName" : "subUser2-1", "roleId" : "role121", "children" : [
{ "roleName" : "subUser2-1-1", "roleId" : "role1211", "children" : [] },
{ "roleName" : "subUser2-1-2", "roleId" : "role1212", "children" : [] }
]}
]}
]},
{ "roleName" : "Admin", "roleId" : "role2", "children" : [] },
{ "roleName" : "Guest", "roleId" : "role3", "children" : [] }
];
//roleList1 to treeview
$scope.roleList = $scope.roleList1;
});
(function(f) {
f.module("angularTreeview", []).directive("treeModel", function($compile) {
return {
restrict: "A",
link: function(b, h, c) {
var a = c.treeId,
g = c.treeModel,
e = c.nodeLabel || "label",
d = c.nodeChildren || "children",
e = '<ul><li data-ng-repeat="node in ' + g + '">
<span data-ng-class="node.selected" data-ng-click="' + a + '.selectNodeLabel(node)">{{node.' + e + '}}</span><div data-ng-hide="node.collapsed" data-tree-id="' + a + '" data-tree-model="node.' + d + '" data-node-id=" + (c.nodeId || "id") + " data-node-label=" + e + " data-node-children=" + d + "></div></li></ul>";<br mode="hold" /> a && g && (c.angularTreeview && (b[a] = b[a] || {}, b[a].selectNodeHead = b[a].selectNodeHead || function(a) {<br mode="hold" /> a.collapsed = !a.collapsed<br mode="hold" /> }, b[a].selectNodeLabel = b[a].selectNodeLabel || function(c) {<br mode="hold" /> b[a].currentNode && b[a].currentNode.selected &&<br mode="hold" /> (b[a].currentNode.selected = void 0);<br mode="hold" /> c.selected = "selected";<br mode="hold" /> b[a].currentNode = c<br mode="hold" /> }), h.html("></div></li></ul>
推荐答案
这篇关于如何在$ http中为Angularjs重写json数组..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!