gpt4 book ai didi

javascript - angular-ui-tree 拖动不起作用

转载 作者:行者123 更新时间:2023-11-30 17:12:39 25 4
gpt4 key购买 nike

我正在尝试使用 angular-ui-tree渲染一棵树。当我拖动“baz”节点时,在“bar”节点下出现 Uncaught TypeError: Cannot read property '$$phase' of null。将任何其他节点拖到任何其他位置都可以正常工作。

我不明白错误消息的含义。我是 Angular 的新手。

这是我的代码:

http://plnkr.co/edit/G3dHRluoAmjiTmPmBZr2?p=preview

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.rawgit.com/JimLiu/angular-ui-tree/master/dist/angular-ui-tree.min.css">

<style>
.angular-ui-tree-placeholder {
background: #f0f9ff;
border: 2px dashed #bed2db;
}
.angular-ui-tree-handle {
background: #f8faff;
border: 1px solid #dae2ea;
color: #7c9eb2;
padding: 10px 10px;
}

</style>

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/JimLiu/angular-ui-tree/master/dist/angular-ui-tree.min.js"></script>
</head>
<body ng-app="treeApp">
<div class="tree_section" ng-controller="treeCtrl">

<!-- Nested node template -->

<script type="text/ng-template" id="nodes_renderer.html">
<div ui-tree-handle class="tree-node tree-node-content">
{{id}} {{nodes[id].text}} {{nodes[id].child_ids}}
</div>
<ol ui-tree-nodes="" ng-model="nodes[id].child_ids">
<li ng-repeat="id in nodes[id].child_ids" ui-tree-node ng-include="'nodes_renderer.html'"></li>
</ol>
</script>

<div ui-tree id="tree-root">
<ol ui-tree-nodes="" ng-model="top_ids">
<li ng-repeat="id in top_ids" ui-tree-node ng-include="'nodes_renderer.html'"></li>
</ol>
</div>

<p>top_ids: {{top_ids}}</p>

<script>
var treeApp = angular.module("treeApp", ['ui.tree']);

treeApp.controller('treeCtrl', ['$scope',
function($scope) {

$scope.nodes = {
'1': {
'text': 'foo',
'child_ids': ['2'],
},
'2': {
'text': 'bar',
'child_ids': [],
}
}
$scope.top_ids = ['1']

$scope.nodes['3'] = {
text:'baz', child_ids:[]
}
$scope.nodes['1'].child_ids.push('3');
}
]);

</script>
</div>
</body>
</html>

最佳答案

andersManden 在 github 问题上提供的解决方案似乎是可行的解决方案,

   $scope.safeApply = function(fn) {
var phase = this.$root.$$phase;
if(phase == '$apply' || phase == '$digest') {
if(fn && (typeof(fn) === 'function')) {
fn();
}
} else if(phase == null){
fn();
} else {
this.$apply(fn);
}
};

关于javascript - angular-ui-tree 拖动不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26686120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com