我正在使用angular-jquery-timepicker directive来填充带有AM / PM格式小时的选择框。
我从这样的JSON中得到这个时间:
[
{
id: "34", day_of_week: "2", start_time: "8:00 AM",
end_time: "12:00 PM", duration: 30
},
…
]
此处,根据文档初始化指令选项:
for(var i = 0; i < httpData.data.length; i++)
{
httpData.data[i].start_time = moment(httpData.data[i].start_time, 'g:i A');
httpData.data[i].end_time = moment(httpData.data[i].end_time, 'g:i A');
httpData.data[i].options = {
step: httpData.data[i].duration,
timeFormat: 'g:i A',
asMoment: true
};
}
$scope.settings = httpData.data;
进入ng-repeat:
<input class="custom-input" ui-timepicker="setting.options" type="text" name="start" ng-model="setting.start_time" required />
<input class="custom-input" ui-timepicker="setting.options" type="text" name="end" ng-model="setting.end_time" required />
问题是循环中生成的start_time和end_time有00:00 hs,因此在selectbox中选择了12:00 AM。
有什么想法吗?
答案 0 :(得分:2)
考虑使用:
> a="\"hello/bye\""
> b="\"one/two\""
> echo $a
"hello/bye"
> echo $b
"one/two"
> echo $a|sed -e 's|'$a'|'$b'|'
"one/two"
而不是
moment(httpData.data[i].start_time, 'hh:mm A');
的完整列表