ios使用jspatch中需要注意的事项

时间:2023-03-09 23:21:44
ios使用jspatch中需要注意的事项

第一份代码,为了纠正原代码不显示29号的bug,先上代码

 require('NSString','MCDatePickType','NSMutableArray','UIButton');

 defineClass('MMCDatePickView',{

     setDatePickViewSelected: function() {

     self.setSelectedYearRow(self.yearArray().indexOfObject(self.currentYearString()));
self.setSelectedDayRow(self.DaysArray().indexOfObject(self.currentDayString()));
self.setSelectedHourRow(self.hoursArray().indexOfObject(self.currentHourString()));
self.setSelectedMinuteRow(self.minutesArray().indexOfObject(NSString.stringWithFormat("%@分", self.currentMinuteString()))); // 设置年和月
var MonthAndYear = self.currentYearString().toJS() + '年' + self.currentMonthString().toJS() + '月'; if (self.type() === 0) { for (var i = 0; i < self.yearArray().count(); i++) { var jsArray = self.yearArray().toJS();
var year = jsArray[i];
if (year == self.currentYearString().toJS()) { self.datePickView().selectRow_inComponent_animated(i, 0, YES); break;
}
} }
else { self.setSelectedMonthRow(self.yearAndMonthArray().indexOfObject(MonthAndYear));
self.datePickView().selectRow_inComponent_animated(self.selectedMonthRow(), 0, YES); if (self.type() !== 0 && self.type() !== 1 && self.type() !== 5) {
self.datePickView().selectRow_inComponent_animated(self.selectedDayRow(), 1, YES);
} //选中小时
if (self.type() === 3 || self.type() === 4) {
self.datePickView().selectRow_inComponent_animated(self.selectedHourRow(), 2, YES);
} //选中分
if (self.type() === 4) {
self.datePickView().selectRow_inComponent_animated(self.selectedMinuteRow(), 3, YES);
} // 选中自定义的
if (self.type() === 5) {
self.datePickView().selectRow_inComponent_animated(self.customerIndex(), 0, YES);
}
}
}
});

注意事项:

1.在对字符或者数组,字典操作的时候应该转成js的字符串或者字典,等等

var MonthAndYear = self.currentYearString().toJS() + '年' + self.currentMonthString().toJS() + '月';

上边的代码是正确的,MonthAndYear 就是js格式的字符串,下边的是不对的:

var MonthAndYear = self.currentYearString() + '年' + self.currentMonthString() + '月';

2.在进行比较的时候,使用相同类型,js的数据类型和oc的不一样

 var jsArray = self.yearArray().toJS();
var year = jsArray[i];
if (year == self.currentYearString().toJS()) { self.datePickView().selectRow_inComponent_animated(i, 0, YES); break;
}

3.js 是弱类型语言,不强调类型,oc的枚举在js中不好使,

self.type() === 0

最终还是把枚举转成了基本数据类型