如何隐藏一行表(或列表项)并更新数据存储区而不重新加载页面?
我有一个桌面上显示的书签列表 。 我添加了一个“隐藏”链接来隐藏我不想在列表中看到的书签,但我仍然想要保留(仅当您登录时才显示表和隐藏链接)。
现在我通过从数据库中获取项目并将其“display”属性更改为“False”并再次呈现页面来实现。
我认为这可以更好地使用javascript完成而无需重新加载页面。 我发现有几个引用隐藏了一行表但不仅仅是隐藏我还需要将新的display属性写入数据库。 我不明白我怎么做到这一点。 隐藏行并将新显示属性写入数据库的最佳方法是什么? 谢谢。
这是我现在的代码:
#-----------main table------------# display = self.request.get("display") main_id = self.request.get("main_id") self.response.out.write(""" links edit tags """) if display == "false": k = Main.get_by_id(int(main_id)) k.display = False k.put() self.redirect("/useradminpage") query = Main.all() query.filter("owner", user) query.filter("display", True) query.order("-date") cursor = self.request.get("cursor") if cursor: query.with_cursor(cursor) e = query.fetch(100) cursor = query.cursor() for item in e: main_id = item.key().id() self.response.out.write(""" https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s (https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s)
https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s (edit) (hide) (comments) https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s """ % tuple([item.url, item.title, urlparse(item.url).netloc, f1.truncate_at_space(item.pitch), main_id, main_id, main_id, item.url, main_id, (", ".join(item.tag_list)), (", ".join(item.tag_list)), ])) self.response.out.write("""
""")
更新
在RobG的回答中尝试style.display
; 但以下代码不起作用:
... for item in e: main_id = item.key().id() self.response.out.write(""" https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s (https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s)
https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s (edit) (hide) (comments) https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s ...
UPDATE
尝试RobG编辑的答案 。 在这种情况下,当我单击隐藏按钮时,该行隐藏片刻然后再次返回。 我不明白为什么。 我粘贴下面的代码,包括持有表:
#-----------holding table start--------# self.response.out.write(""" """) self.response.out.write(""" """) #-----------tags table start--------# self.response.out.write(""" tags
alpha
newest
popular """) if order_by == "popular": for tag in most_used: self.response.out.write(""" https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s """ % (tag, tag)) else: for tag in unique_tags: self.response.out.write(""" https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s """ % (tag, tag)) self.response.out.write("""
""") #holding table first column end self.response.out.write(""" """) #holding table second column start self.response.out.write("""""") #-----------main table------------# display = self.request.get("display") main_id = self.request.get("main_id") self.response.out.write(""" links edit tags """) query = Main.all() query.filter("owner", user) #query.filter("display", True) query.order("-date") cursor = self.request.get("cursor") if cursor: query.with_cursor(cursor) e = query.fetch(100) cursor = query.cursor() for item in e: main_id = item.key().id() self.response.out.write(""" https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s (https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s)
https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s (edit) (hide) (comments) https://stackoverflow.com/questions/7669256/how-to-hide-a-row-of-table-or-a-list-item-and-update-the-datastore-without-rel/%s """ % tuple([item.url, item.title, urlparse(item.url).netloc, f1.truncate_at_space(item.pitch), main_id, main_id, main_id, item.url, main_id, (", ".join(item.tag_list)), (", ".join(item.tag_list)), ])) self.response.out.write("""
""") #holding table end self.response.out.write('More Results' % cursor) self.response.out.write(""" """) self.response.out.write("""
""") self.response.out.write("""