【发布时间】:2015-03-14 01:04:53
【问题描述】:
我正在尝试使用下划线 .uniq 对数组进行排序,但它返回的数组与未排序的数组相同。我认为这是因为它是按 id 排序的,但我不确定。如果它是按 id 排序的,我如何让它沿着与查询相同的行进行排序(allCategories 是“主”列中的所有值),该查询基于我的 Parse 集合 bizCategories 中的主列?
我的代码:
var Categories = Parse.Object.extend("bizCategories");
var categories = new Categories();
$scope.primarySelect = function() {
var primary = new Parse.Query(Categories);
primary.find({
success:function(list){
$scope.allCategories = _.uniq(list)
console.log($scope.allCategories);
}
})
}
$scope.primarySelect();
解析集合列'primary':
【问题讨论】:
-
您没有显示您正在使用的数据。尝试类似 $scope.allCategories = _.uniq(list,'primary') 的方法,其中 primary 是列表中对象的属性。
-
每当我使用 _.uniq 时,我都会得到以下三个响应之一:1)
-
每当我使用 .uniq (有时与 _.chain 一起使用)时,我都会得到三个响应之一:1) _.uniq(list, primary).map(iteratee) 返回一个对象(应该有 13 个,由独立的 excel 函数验证)。 2) Uncaught TypeError: undefined is not a function (在大多数情况下) 2 _ {_wrapped: Array[100], _chain: true, after: function, all: function, any: function...} 3) (当使用chain then map然后 uniq 在 iteratee) function () { var args = [this._wrapped]; push.apply(参数,参数); return result.call(this, func.apply(, args)); }
-
好的,经过一番修改,我明白你的意思并让它工作了。谢谢!
标签: arrays sorting parse-platform underscore.js