Ваш пример кода является неправильным. Это работает:
import datetime
datetime.datetime.strptime("21/12/2008", "%d/%m/%Y").strftime("%Y-%m-%d")
вызов к strptime () анализирует первый аргумент согласно формату, указанному во втором, таким образом, те два должны соответствовать. Затем можно назвать strftime () для форматирования результата в желаемый заключительный формат.
Inside the function provided to each
, this
refers to the current element. Try this:
$.each(result.GroupList, function() {
$('#myTable > tbody').append(
'<tr><td>'
+ this.userName
+ '</td><td>'
+ this.count +
'</td></tr>'
);
});
If that doesn't work for you, it may have something to do with this: $('#myTable > tbody')
, considering that there is no tbody
element. I believe that Internet Explorer will automatically create one but the other browsers won't. Check $.support.tbody
to see if the browser does that for you.
I noticed your table does not actually have a tbody element. This could be part of your issue.
$('#myTable > tbody').append.....
<table id="myTable" border="2" cellpadding="3" cellspacing="3">
</table>
I would also suggest that you create a string in your $.each() loop and then do the following after your each loop:
$('#myTable > tbody').html(string);
This will reduce the overhead of appending each time you iterate over the array.
Когда я использовал $ .each (), я использовал функцию (i, item), где i - целое число, указывающее индекс, а item - это фактический объект. Вот как документация показывает, что это делается - метод описан как обратный вызов функции (indexInArray, valueOfElement).