gpt4 book ai didi

javascript - Angularjs View 不更新,单击按钮时 View 闪烁

转载 作者:行者123 更新时间:2023-11-30 10:04:18 26 4
gpt4 key购买 nike

我编写了以下 HTML 和 AngularJS 代码,以在单击按钮时更新 HTML 页面( View )上的树。

单击按钮时,更改会出现几分之一秒然后消失。我找不到原因。你能告诉我如何解决这个问题吗?

下面是 HTML 和 JS 代码。这在代码段编辑器中有效,但在浏览器中无效。

var module = angular.module('myapp', []);

module.controller("TreeCtrl", function($scope) {
$scope.categories = [];


$scope.$apply($scope.addTreeToView = function() {

$scope.categories = [{
title: 'Computers1',
categories: [{
title: 'Laptops1',
categories: [{
title: 'Ultrabooks1'
}, {
title: 'Macbooks1'
}]
}, {
title: 'Desktops1'
}, {
title: 'Tablets1',
categories: [{
title: 'Apple1'
}, {
title: 'Android1'
}]
}]
}, {
title: 'Printers1',
categories: [{
title: 'HP1'
}, {
title: 'IBM1'
}]
}];



});
});
<!DOCTYPE html>
<html lang="en">

<head>
<title>Tree Example</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>

<body>
<div ng-app="myapp">
<div class="col-sm-10 col-sm-offset-1" ng-controller="TreeCtrl">

<form action="#" method="post" class="form-horizontal" id="commentForm" role="form">
<div class="form-group" id="div_submitComment">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-success btn-circle text-uppercase" type="submit" ng-click="addTreeToView()"><span class="glyphicon glyphicon-send" id="qazwsx"></span> Create Tree</button>
</div>
</div>
</form>

<div class="page-header">
<h3 class="reviews">Tree</h3>
</div>

<script type="text/ng-template" id="categoryTree">
{{ category.title }}
<ul ng-if="category.categories">
<li ng-repeat="category in category.categories" ng-include="'categoryTree'">
</li>
</ul>
</script>

<ul>
<li ng-repeat="category in categories" ng-include="'categoryTree'"></li>
</ul>


</div>
</div>
<script src="self.js"></script>
</body>

最佳答案

尝试从按钮中删除 type="submit"

关于javascript - Angularjs View 不更新,单击按钮时 View 闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30107743/

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