Javascript ng在ng重复中单击不点火?
好的,我有以下几点:Javascript ng在ng重复中单击不点火?,javascript,angularjs,Javascript,Angularjs,好的,我有以下几点: scope.monthpickerclick = function(scope){ $window.alert('test'); console.log(scope); }; scope.monthpicker = function(alldatesdumparray){ var alldatesdump = booking.getalldates(); var alldatesdumparray = $.map(booking.
scope.monthpickerclick = function(scope){
$window.alert('test');
console.log(scope);
};
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;
}
});
return singles;
};
scope.monthpickerclick=函数(范围){
$window.alert('test');
console.log(范围);
};
scope.monthpicker=函数(alldatesdumparray){
var alldatesdump=booking.getalldates();
var alldatesdumparray=$.map(booking.getalldates(),函数(值,索引){
var dropdates=新日期(value.Date);
var dropdate=dropdates.getDate();
var month=新数组();
月[0]=“一月”;
月[1]=“2月”;
月[2]=“三月”;
月[3]=“4月”;
月[4]=“五月”;
月[5]=“6月”;
月[6]=“7月”;
月[7]=“8月”;
月[8]=“9月”;
月[9]=“10月”;
月[10]=“11月”;
月[11]=“12月”;
var dropmonth=month[dropdates.getMonth()];
var checkmonth=dropdates.getMonth();
var dropyear=dropdates.getFullYear();
var joindates=dropmonth+'-'+dropyear;
var monthyear=checkmonth+'-'
var today=新日期();
var mm=today.getMonth();//一月是0!
var yyyy=today.getFullYear();
如果(mm
HTML:
<select >
<option ng-click="monthpickerclick()" class="animate-repeat" ng-repeat="returnpicker in monthpicker(singles)" value="{{returnpicker.date}}">{{returnpicker.date}}</option>
</select>
{{returnpicker.date}
哪些产出:
<select>
<!-- ngRepeat: returnpicker in monthpicker(singles) -->
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="January-2014">January-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="February-2014">February-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="March-2014">March-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="April-2014">April-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="May-2014">May-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="June-2014">June-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="July-2014">July-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="August-2014">August-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="September-2014">September-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="October-2014">October-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="November-2014">November-2014</option>
<option ng-click="monthpickerclick()" class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(singles)" value="December-2014">December-2014</option>
</select>
2014年1月
2014年2月
2014年3月
2014年4月至4月
2014年5月至5月
2014年6月
2014年7月
2014年8月
2014年9月
2014年10月
2014年11月
2014年12月
看起来不错。。。
那么,当我选择一个选项时,为什么monthpickerclick()不触发呢?
Chris主要问题是您应该将这些功能附加到选择项,而不是选项并使用ng change
<select ng-change="monthPickerClick()" >
<option class="animate-repeat" ng-repeat="returnpicker in monthpicker(singles)" value="{{returnpicker.date}}">{{returnpicker.date}}</option>
</select>
{{returnpicker.date}
编辑:加入你的建议
<select ng-change="monthPickerClick()" ng-model="myItem">
<option class="animate-repeat" ng-repeat="returnpicker in monthpicker(singles)" value="{{returnpicker.date}}">{{returnpicker.date}}</option>
</select>
$scope.$watch('myItem', function(){
//do something
});
{{returnpicker.date}
$scope.$watch('myItem',function(){
//做点什么
});
第二次编辑:
<select ng-change="monthPickerClick()" ng-model="myItem" ng-init="savedReturnPicker=[]">
<option class="animate-repeat" model="savedReturnPicker[returnpicker.date]" ng-repeat="returnpicker in monthpicker(singles)" value="{{returnpicker}}">{{returnpicker.date}}</option>
</select>
//save the returnPicker to a model called savedReturnPicker, then look up with $scope.savedReturnPicker[someDateGoesHere}
{{returnpicker.date}
//将returnPicker保存到名为savedReturnPicker的模型,然后使用$scope.savedReturnPicker[SomeDateGoesher}进行查找
您是否尝试过
?它需要ng模型,而我在本例中没有此模型…看起来您的函数期望传递某些内容,但在ng单击时,它没有传递任何内容。此外,请将$
放在您的定义前面。我的函数至少应该发出警报…您真正需要的是ng model=“something”
和$scope.$watch('something',function(){…})
。我如何返回对象returnpicker而不仅仅是myitme中选项的值…呢?是否有example函数?再次编辑。初始化数组,savedReturnPicker=[],然后附加到一个名为该名称的模型上,并按您的.date进行索引。这里还有更多的工作要做,但我想您已经明白了。我刚刚添加了另一个问题,如果您想用这个JSFIDLE或类似的东西来回答,请,这样更容易帮助。