JSON.stringify を使用して文字列に変換された配列があるため、ajax によってデータを Python ハンドラーに送信できます。これにより、データを文字列として保存することができました...大括弧、引用符、およびすべて。このデータは、文字列だけでなく、ある種の使用可能なリストまたは配列で必要です。よろしくお願いします。
データベースに保存される文字列の形式 (データストア - GAE を使用):
["SU15AM","SU3AM","SU4AM","SU45AM","SU4PM","M3AM"]
JavaScript/ajax コード:
var ids = new Array();
$('.ui-selected').each(function(){
ids.push($(this).attr('value')); //adds items selected to the array so that they can be passed via ajax
console.log('**item added to data object**');
});
string_ids = JSON.stringify(ids, null); //converts array object to a string to pass via ajax
$.ajax({
type: "POST",
url: '/schedule',
data: {'ids': string_ids}, //string of selected items
});
Python ハンドラ:
class ScheduleHandler(BaseHandler2):
time_ids = self.request.get('ids')
times = AvailableTimes(ids = time_ids)
times.put();
Python モデル:
class AvailableTimes(db.Model):
user = db.StringProperty()
timezone = db.StringProperty()
ids = db.StringProperty()