gpt4 book ai didi

javascript - 在 ng-options 中将默认值设置为第一个?

转载 作者:行者123 更新时间:2023-12-02 17:53:59 24 4
gpt4 key购买 nike

好的,我有这个:

    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>

我如何分配项目以获得选项中可用的第一个值...

最佳答案

您可以将 ng-options 中的值分配给您选择的 ng-model(即 $socpe.item)。

在你的 Controller 中:

$scope.item = 月份[0];

关于javascript - 在 ng-options 中将默认值设置为第一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21123911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com