Ich habe einen Fehler mit einem Versprechen. Ich versuche angular-tree-dnd zu verwenden, aber ich habe ein Problem mit einem Versprechen.Geben Sie ein Versprechen mit einem Modell und einem Service zurück
von meinem Controller:
project.getAll().then(function(results) {
var projects = results;
$scope.results = [];
angular.forEach(projects, function(result) {
$scope.results.push(project.build(result));
});
return $scope.results;
});
$scope.tree_data = $TreeDnDConvert.line2tree($scope.results, 'id', 'ParentId');
mein Modell:
var Project = function(properties) {
// Model
this.description = null;
this.file = null;
this.name = null;
this.ParentId = null;
this.path = null;
angular.extend(this, properties);
};
Project.prototype.setModel = function(obj) {
angular.extend(this, obj);
};
Project.prototype.getAll = function() {
return ProjectService.getAll();
};
Project.prototype.build = function(data) {
var project = new Project(data);
return project;
};
meinen Dienst (mit $ WebSQL):
this.getAll = function(params) {
var projects = [];
return db.selectAll('projects').then(function(results) {
for (var i = 0; i < results.rows.length; i++) {
projects.push(results.rows.item(i));
}
return projects;
});
};
Ich habe keinen Fehler, aber mein Haus ist leer.
habe ich versucht, dies:
project.getAll().then(function(results) {
var projects = results;
$scope.results = [];
angular.forEach(projects, function(result) {
$scope.results.push(project.build(result));
});
return $scope.results;
}).then(function(array) {
$scope.tree_data = $TreeDnDConvert.line2tree(array, 'id', 'ParentId');
});
Aber ich habe diesen Fehler:
angular.min.js:13550 TypeError: Cannot read property '__children__' of undefined
at Object._$initConvert.line2tree (ng-tree-dnd.js:1456)
Ich denke, dass mein Array
Wo ist 'project.build' definiert? Was gibt es zurück? Ich denke, das ist der Kern Ihres Problems. – JLRishe
In meinem Modell habe ich meinen Code –