好的,我有这个:
scope.$watch('item', function(){
var getmonthdrop = scope && scope.item && scope.item.month;
var getyeardrop = scope && scope.item && scope.item.Year;
// scope.month = getmonthdrop;
// scope.year = getyeardrop;
console.log( getmonthdrop + '-' + getyeardrop);
});
scope.monthpicker = function(alldatesdumparray){
var alldatesdump = booking.getalldates();
var alldatesdumparray = $.map(booking.getalldates(), function(value, index) {
var dropdates = new Date(value.date);
var dropdate = dropdates.getDate();
var month=new Array();
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
var dropmonth = month[dropdates.getMonth()];
var checkmonth = dropdates.getMonth();
var dropyear = dropdates.getFullYear();
var joindates = dropmonth + '-' + dropyear;
var monthyear = checkmonth + '- '
var today = new Date();
var mm = today.getMonth(); //January is 0!
var yyyy = today.getFullYear();
if(mm < checkmonth && dropyear < yyyy){
}else{
value.date = joindates;
value.month = checkmonth;
value.Year = dropyear;
return [value];
}
});
//console.log(alldatesdumparray);
var dupes = {};
var singles = [];
$.each(alldatesdumparray, function(i, el) {
if (!dupes[el.date]) {
dupes[el.date] = true;
singles.push(el);
return singles;
}
});
/*scope.item = singles[0] && singles[0].date;
console.log(scope.item);
console.log(singles[0]);*/
return singles;
};
//console.log(monthpicker(singles));
//scope.item = {scope.monthpicker[0].value};
使用这个html:
<select ng-model="item" ng-options="o as o.date for o in monthpicker(singles)"></select>
总是返回第一个null值: 像这样:
<select ng-model="item" ng-options="o as o.date for o in monthpicker(singles)" class="ng-pristine ng-valid">
<option value="?" selected="selected"></option>
<option value="0">January-2014</option>
<option value="1">February-2014</option>
<option value="2">March-2014</option>
<option value="3">April-2014</option>
<option value="4">May-2014</option>
<option value="5">June-2014</option>
<option value="6">July-2014</option>
<option value="7">August-2014</option>
<option value="8">September-2014</option>
<option value="9">October-2014</option>
<option value="10">November-2014</option>
<option value="11">December-2014</option>
</select>
如何指定项目以使选项中的第一个值可用...
答案 0 :(得分:2)
您可以从$socpe.item
为您的选择的ng模型(ng-options
)分配值。
在您的控制器中:
$scope.item = month[0];