Angularjs angular.js-从视图更新模型中的排序器

Angularjs angular.js-从视图更新模型中的排序器,angularjs,mongodb,express,model,controller,Angularjs,Mongodb,Express,Model,Controller,我有一个Express模型/控制器,从mongoDB集合获取数据。这个集合中的一列是sortOrder(我使用它按特定顺序显示条目)。为了管理这个集合中的数据,我有一个angular.js视图和一个表,列出了这些条目 此表是使用ui sortable构建的,它允许我拖放表行,即更改显示顺序。到目前为止,一切正常 现在,我的问题是:如何让我的模型/控制器识别这些更改,并更新集合中的sortOrder列,以显示新的排序顺序 以下是视图的代码: <section data-ng-controll

我有一个Express模型/控制器,从mongoDB集合获取数据。这个集合中的一列是sortOrder(我使用它按特定顺序显示条目)。为了管理这个集合中的数据,我有一个angular.js视图和一个表,列出了这些条目

此表是使用ui sortable构建的,它允许我拖放表行,即更改显示顺序。到目前为止,一切正常

现在,我的问题是:如何让我的模型/控制器识别这些更改,并更新集合中的sortOrder列,以显示新的排序顺序

以下是视图的代码:

<section data-ng-controller="BusinessunitsController" data-ng-init="find()">
    <div class="page-header">business units</div>
    <table>
        <thead>
            <tr>
                <th><i class="icon-fontawesome-webfont-141"></i></th>
                <th>business unit name</th>
                <th><a href="/#!/businessunits/create"><i class="icon-fontawesome-webfont-241 right"></i></a></th>
            </tr>
        </thead>
        <tbody ui-sortable ng-model="businessunits">
            <tr data-ng-repeat="businessunit in businessunits">
                <td class="draggable">{{businessunit.sortOrder}}</td>
                <td style="color:{{businessunit.color}}">{{businessunit.name}}</td>
                <td>
                    <a data-ng-href="#!/businessunits/{{businessunit._id}}"><i class="icon-fontawesome-webfont-65"></i></a>
                    <a data-ng-href="#!/businessunits/{{businessunit._id}}"><i class="icon-fontawesome-webfont-240 alert"></i></a>
                </td>
            </tr>
        </tbody>
    </table>
 </section>
快速控制器:

'use strict';

// Businessunits controller
angular.module('businessunits').controller('BusinessunitsController', ['$scope', '$stateParams', '$location', 'Authentication', 'Businessunits',
    function($scope, $stateParams, $location, Authentication, Businessunits) {
        $scope.authentication = Authentication;

        // Create new Businessunit
        $scope.create = function() {
            // Create new Businessunit object
            var businessunit = new Businessunits({
                name: this.name,
                color: this.color,
                sortOrder: this.sortOrder
            });

            // Redirect after save
            businessunit.$save(function(response) {
                $location.path('businessunits/' + response._id);
            });

            // Clear form fields
            this.name = '';
        };

        // Remove existing Businessunit
        $scope.remove = function(businessunit) {
            if (businessunit) {
                businessunit.$remove();

                for (var i in $scope.businessunits) {
                    if ($scope.businessunits[i] === businessunit) {
                        $scope.businessunits.splice(i, 1);
                    }
                }
            } else {
                $scope.businessunit.$remove(function() {
                    $location.path('businessunits');
                });
            }
        };

        // Update existing Businessunit
        $scope.update = function() {
            var businessunit = $scope.businessunit;

            businessunit.$update(function() {
                $location.path('businessunits/' + businessunit._id);
            });
        };

        // Find a list of Businessunits
        $scope.find = function() {
            Businessunits.query(function(businessunits) {
                $scope.businessunits = businessunits;
            });
        };

        // Find existing Businessunit
        $scope.findOne = function() {
            Businessunits.get({
                businessunitId: $stateParams.businessunitId
            }, function(businessunit) {
                $scope.businessunit = businessunit;
            });
        };
    }
]);
'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    Businessunit = mongoose.model('Businessunit'),
    _ = require('lodash');

/**
 * Create a Businessunit
 */
exports.create = function(req, res) {
    var businessunit = new Businessunit(req.body);
    businessunit.user = req.user;

    businessunit.save(function(err) {
        if (err) {
            return res.send('users/signup', {
                errors: err.errors,
                businessunit: businessunit
            });
        } else {
            res.jsonp(businessunit);
        }
    });
};

/**
 * Show the current Businessunit
 */
exports.read = function(req, res) {
    res.jsonp(req.businessunit);
};

/**
 * Update a Businessunit
 */
exports.update = function(req, res) {
    var businessunit = req.businessunit;

    businessunit = _.extend(businessunit, req.body);

    businessunit.save(function(err) {
        if (err) {
            res.render('error', {
                status: 500
            });
        } else {
            res.jsonp(businessunit);
        }
    });
};

/**
 * Delete an Businessunit
 */
exports.delete = function(req, res) {
    var businessunit = req.businessunit;

    businessunit.remove(function(err) {
        if (err) {
            res.render('error', {
                status: 500
            });
        } else {
            res.jsonp(businessunit);
        }
    });
};

/**
 * List of Businessunits
 */
exports.list = function(req, res) {
    Businessunit.find().sort('sortOrder').populate('user', 'name').exec(function(err, businessunits) {
        if (err) {
            res.render('error', {
                status: 500
            });
        } else {
            res.jsonp(businessunits);
        }
    });
};

/**
 * Businessunit middleware
 */
exports.businessunitByID = function(req, res, next, id) {
    Businessunit.findById(id).populate('user', 'name').exec(function(err, businessunit) {
        if (err) return next(err);
        if (!businessunit) return next(new Error('Failed to load Businessunit ' + id));
        req.businessunit = businessunit;
        next();
    });
};

/**
 * Businessunit authorization middleware
 */
exports.hasAuthorization = function(req, res, next) {
    if (req.businessunit.user.id !== req.user.id) {
        return res.send(403, 'User is not authorized');
    }
    next();
};

您能同时发布BusinessUnits控制器代码吗?@Tone,我已经添加了Express和Angular控制器。