0
我有这2个功能,如何使用ngOptions函数?
function functionCall(orderByRelease_date){
orderByClick = "release_date"
orderBy();
console.log ('release')
}
function functionCall(orderByCreated_at){
orderByClick = "created_at"
orderBy();
console.log ('created')
}
这些功能设置变量orderByClick
此功能,
var orderBy = function(){
$scope.movies = response.data;
var orderBy = $filter('orderBy');
$scope.orderedMovies = orderBy($scope.movies, orderByClick);
var movies = $scope.orderedMovies
var i,j,temparray,chunk = 8, movieGroups=[];
for (i=0,j=movies.length; i<j; i+=chunk) {
temparray = movies.slice(i,i+chunk);
movieGroups.push(temparray);
}
$scope.movieGroupsSuggestions = movieGroups
}
我创造了一个选项列表这样,
%select
%option{:onselect => "functionCall(orderByRelease_date)"} Sort by release date.
%option{:onselect => "functionCall(orderByCreated_at)"} Sort by newest
但似乎没有做任何事情。
所以我偶然发现了ngoptions,它似乎是一条路,但我不清楚我如何使用它的功能。
我已经创建了选项的范围,
$scope.orderList = [
'created_at',
'release_date'
]
而一个NG选项元素,
%select{"ng-options" => "option for option in orderList"}
这显示从orderList的值,但我怎么挂钩这件事使我的orderBy
函数中的变量oderByClick
是否发生变化?
你是否使用ng-repeat with orderBy –
不确定你的意思。但我使用js代码(orderBy函数)来创建包含电影对象的行。所以ng-repeat不起作用。 –
您需要将'ng-model'指令添加到您选择的元素。 – georgeawg