我已经做了一些研究,我似乎无法找到最好的模式来ng-repeat递归使用来创建一个深度table.用户mgdelmonte在这里有一些值得注意的关于这个主题的提及,但是唉,没有解决方案.
HTML和模板:
<body ng-app="myApp">
<div ng-controller="myAppController">
<script type="text/ng-template" id="tree_item.html">
<tr style="width:100%">
<td>{{data.name}}</td>
</tr>
<div ng-repeat="data in data.nodes" ng-include="'tree_item.html'">
</div>
</script>
<table class="table table-striped">
<thead>
<tr>
<th style="width:30px;">Test</th>
</tr>
</thead>
<tbody ng-repeat="data in treeData" ng-include="'tree_item.html'">
</tbody>
</table>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
JS:
angular.module('myApp', []);
function myAppController($scope) {
$scope.treeData = [{
"name": "Root",
"nodes": [{
"name": "Level 1",
"nodes": [{
"name": "Level 2"
}]
}]
}];
}
Run Code Online (Sandbox Code Playgroud)
这是我的jsfiddle:http://jsfiddle.net/8f3rL/86/
这是我得到的绝对最远的.它可以很好地遍历树,但是<tr>当它递归时,我正在丢失标签.而是它的渲染<span>.
我的直觉告诉我,当它ng-repeat …
当包依赖项发生变化时,我试图加快我的纱线安装类型。我试图重现这个问题的核心。
package.json(随机包,示例)
{
"name": "docker-cache",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"colors": "^1.4.0",
"deep-equal": "2.0.3",
"dotenv": "8.2.0",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",
"eslint-config-react-app": "^6.0.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-flowtype": "^5.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"exceljs": "^4.2.1",
"fast-check": "^1.24.2",
"file-loader": "6.0.0",
"find": "0.3.0",
"fs-extra": "9.0.1",
"html-webpack-plugin": "4.3.0",
"jest": "26.2.2",
"jest-canvas-mock": "2.2.0",
"jest-pnp-resolver": "^1.2.1",
"json-diff": "0.5.4",
"lerna": "^3.22.1",
"madge": "^5.0.1",
"mini-css-extract-plugin": …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
someService.fnReturnsPromise()
.then(function () {
return someService.fnReturnsAnotherPromise(someArg);
})
.then(function (resultsOfSecondFn) {
// do stuff with results
});
Run Code Online (Sandbox Code Playgroud)
我觉得这应该有效; 然而,resultsOfSecondFn实际上并不是结果,而是我回来的承诺本身.为了让它按照我想要的方式工作,我必须这样做:
someService.fnReturnsPromise()
.then(function () {
return someService.fnReturnsAnotherPromise(someArg);
})
.then(function (promiseReturn) {
promiseReturn.then(function (results) {
// do stuff with results
});
});
Run Code Online (Sandbox Code Playgroud)
这是伪代码fnReturnsAnotherPromise:
someService.fnReturnsAnotherPromise = function (arg1) {
return anotherService.anotherFnThatReturnsPromise(arg1);
};
Run Code Online (Sandbox Code Playgroud)
所以真的,它只是一个额外的层,但承诺是以任何一种方式返回.代码anotherFnThatReturnsPromise是一些简单的范例$q.defer(),return dfd.promise有些resolve()是s.