gpt4 book ai didi

javascript - 将行附加到嵌套行问题?

转载 作者:行者123 更新时间:2023-12-02 15:05:13 25 4
gpt4 key购买 nike

我正在制作一个带有嵌套行的表格。

问题是,当我将子行附加到父行时,所有其他父行也会附加子行。

使用功能:

$scope.templates=[{src:'template'}];
$scope.include = function(templateURI) {
$scope.templates.push({src:templateURI});
}

追加行:

<button class="btn btn-default btn-sm ng-scope" ng-click="include('rowInRow.html')">
<i class="glyphicon glyphicon-upload"></i>
</button>

显示模板:

<div ng-repeat="template in templates">
<div ng-include="template.src">My template will be visible here</div>
</div>

有人可以给我提示吗?我尝试自己做,但没有找到我需要的东西。

最佳答案

试试这个:http://plnkr.co/edit/ZzPF7UFjKyp2tqn27cf4?p=preview

所有项目都共享templates集合。通过为每个项目提供自己的 templates 数组并迭代该数组来解决此问题。

include 函数设为:

$scope.include = function(project, templateURI) {
if (!project.templates)
project.templates = [];
project.templates.push({src:templateURI});
}

这样调用它:

<button class="btn btn-default btn-sm ng-scope" ng-click="include(project, 'rowInRow.html')">
<i class="glyphicon glyphicon-upload"></i>
</button>

像这样显示:

<div ng-repeat="template in project.templates">
<div ng-include="template.src">My template will be visible here</div>
</div>

关于javascript - 将行附加到嵌套行问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35163241/

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