如何正确创build像trello,Mongoose和Angularjs的卡片显示

我不知道,我已经尝试了一切。

我想这样做下的列表中添加和显示卡的顺序和显示从上升位置。

我必须这样做,以便以后可以添加拖放操作。 这将计算我放置的项目和下面的索引项目的平均位置。

我不能在ng-repeat循环中进行sorting,因为稍后显示的索引不匹配数组元素。 我试图在nodejssorting,但没有按照它应该sorting。

在mongoose数据库中,我这样做了:\

名单

** name:{type:String,maxlength:20,required:true},**

var CardSchema = new Schema({ list: { type: Schema.Types.ObjectId, ref: 'List' }, name: { type: String, maxlength: 20, required: true }, position: { type: Number }, // description: { type: String, maxlength: 300 }, updated: { type: Date, default: Date.now }, created: { type: Date, default: Date.now }, active: Boolean }); 

console.log响应

我正在通过一个AJAX查询数组下载卡[对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,4更多…]

console.log响应elem [0]

对象{_id:“59bfeea368054710181c0c0d”,名称:“ostatni”,列表:“59bbdf061ebcd215a4b7af63”,__v:0,创build:“2017-09-18T16:04:51.457Z”,更新:“2017-09-18T16:04: 51.457Z“}

它看起来像这样:

View post on imgur.com

index.ejs

 <div ng-repeat="list in lists"> <div style="float: left; margin-left: 5px;"> <div id="tasks" > <h3>{{ list.name }}</h3> <ul> <li ng-repeat="card in cards " ng-if="list._id == card.list">{{ card.name }} {{ card.position }}<button ng-click="take($index)">HERE</button>{{ $index }}</li> </ul> <form ng-submit="addTask(list._id, $index, newTask)"> <input type="text" ng-model="newTask" placeholder="add a new task" required /> </form> </div> </div> </div> 

控制器片

 $scope.loadLists = function () { return ApiService.staff.list() .then(function (resp) { for (var i = 0; i < resp.length; i++) { $scope.lists[i] = resp[i]; } }) } $scope.loadsCards = function () { return ApiService.staff.cards() .then(function (resp) { $scope.cards = resp; // for (var i = 0; i < resp.length; i++) { // console.log($scope.cards[i].name) // } console.log($scope.cards[0]) }) } 

谢谢 !