我正在使用过滤器从中继器中提取id。这一切运作良好,但在控制台中我收到以下错误:
https://docs.angularjs.org/error/$interpolate/interr?p0=%7B%7BspecsList%20%7C%20splitIds%7D%7D&p1=TypeError:%20Cannot%20read%20property%20%27map%27%20of%20undefined
如果我更换$http.get
静态值specsList,没有错误。任何想法如何以良好的方式解决它?
JS:
app.controller('SpecsController', function ($scope, $http) {
$scope.$on('$viewContentLoaded', function(event) {
$http.get('getSpecs.aspx')
.then(function(result) {
$scope.specsList = result.data.specs;
})
.catch(function(err) {
console.log(err);
});
});
$scope.sortableOptions = {
handle: "> .position",
helper: function (e, ui) {
var originals = ui.children();
var clonedHelper = ui.clone();
clonedHelper.children().each(function(index) {
//$(this).width($(this).width());
$(this).width(originals.eq(index).outerWidth());
$(this).addClass("dragging");
$(this).parent().addClass("dragging_tr");
});
return clonedHelper;
},
update: function(e, ui) {
//console.log("update");
},
stop: function(e, ui) {
//Save sortorder
}
};
});
app.filter('splitIds', function() {
return function(ArrayWithIds) {
return ArrayWithIds.map(function(item){return item.id;}).join();
};
});
HTML:
<input type="text" value="{{specsList | splitIds}}" />
谢谢!真的很感激它! – peta 2014-09-10 17:57:59