0
我在我的控制下角對象AngularJS獲取屬性值
$scope.students = [{:id => 1, :state => 'active'}, {:id => 2, :state => 'suspended'}]
我怎樣才能讓所有的學生,其狀態是活躍的ID?任何人都可以幫助我嗎?
我在我的控制下角對象AngularJS獲取屬性值
$scope.students = [{:id => 1, :state => 'active'}, {:id => 2, :state => 'suspended'}]
我怎樣才能讓所有的學生,其狀態是活躍的ID?任何人都可以幫助我嗎?
有多種方式,但我能想到的最簡單的就是在你的範圍內添加activeStudent功能,這樣的事情:
$scope.activeStudent = function(){
return _.filter($scope.students, function(s){
return s.state == "active";
});
}
和你的意見,你會在你的綁定使用activeStudent()。
非常感謝Schmurfy!有沒有更好的方式來獲得所有學生的ID而不是循環和收集ID?像** $ scope.students.collect(&:id)**再次感謝! –
我使用下劃線和angularjs,我對它很滿意(我在例子中使用了它),你可以看看http://underscorejs.org/#map和http://underscorejs.org/#pluck。 – Schmurfy