获取动态锚定标记的值并将其传递到下一页 [英] Get the value of the dynamic anchor tag and pass it to the next page

查看:105
本文介绍了获取动态锚定标记的值并将其传递到下一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Tornado框架的Web应用程序。目前我正在研究前端视图。
此页面实际上显示了有关该ID的ID和小记事项列表。 (它是一个有两列的表)




id --------注意



100 -----附注100



101 -----关于101 $的注释




![带有id和id的链接的表格] [1]



动态显示。当我点击id(它是一个链接锚点标记)时,它应该带我到另一个页面,其中包含有关该id的所有详细信息。



方法 - 我认为创建一个cookie,它将存储被点击的id的值,并获取龙卷风处理程序中的cookie,并检索关于该id的所有信息并将其发送到下一个视图。



目前的代码是 -

HTML

 < table class =table table-stripedid =tableid> 
< tbody>
< tr>
< th>配置ID< / th>
< th>注意< / th>
< / tr>

< tr>
{%for d in data%}

< td>
< td> {{d [1]}}< / td>
{%end%}
< / tr>
< tbody>

< / table>
< / div>

所以点击链接就会存储id的值,然后链接指向一个处理程序,我可以获取cookie并获取有关该id的更多信息。



JavaScript

 < script type =text / javascript> 
函数configidCreateCookieFunction(){
var cid = document.getElementById(configid)。innerHTML;
sessionStorage ['configid'] = cid
}



Tornado代码 -

  class SelectedConfigHandler(BaseHandler):
def get (self):
configid = None
configid = self.get_cookie(configid)
print configid

但这不起作用。当我打印id -its显示为无。



所以基本上我不能拉出链接的id的值,而id基本上是来自数据库
请帮助我。我的方法是否正确?



在此先感谢

解决方案

数据库在哪里?因为您使用 id 为什么不访问数据库,比如 MongoDB



你必须知道,cookie将被发送和接收到你的 http 消息,所以你必须意识到这一点,除非你想让一个本地存储,但在这里,您必须保证,您的用户使用 HTML5 浏览器,并发送数据第一次存储在客户端。



因此,我建议使用数据库,并使用隐藏的<输入> ,值是 id


I am developing a web application using Tornado framework. Currently I am working on a front end view. This page actually displays a list of ids and a small note about that id. (Its a table with two columns)


id -------- Note

100 ----- Note on 100

101 ----- Note on 101


![Table with link on id and note on id][1]

The ids are displayed dynamically. When I click on the id (its a link- anchor tag), it should take me to another page which has all the details about that id.

Approach - I thought of creating a cookie which will store the value of the id clicked, and get the cookie in tornado handler and retrieve all information about that id and send it to the next view.

The code so far is -

HTML

                <table class="table table-striped" id="tableid">
                    <tbody>
                        <tr>
                          <th>Config ID</th>
                           <th>Note</th>
                        </tr>

                       <tr>
                            {% for d in data %} 

                            <td>
                            <a onclick = "configidCreateCookieFunction()" href="/SelectedConfig"       name = "configid" id ="configid">{{ d[0] }}</a></td>
                                <td> {{ d[1]}}</td>
                              {% end %}
                            </tr>
                        <tbody>

                </table>
            </div>

So on clicking the link it would store the value of the id, and then the link points to a handler where I can get the cookie and retrieve more information about that id.

JavaScript

<script type="text/javascript">
 function configidCreateCookieFunction(){
  var cid = document.getElementById("configid").innerHTML;
  sessionStorage ['configid'] = cid
  }

Tornado code -

class SelectedConfigHandler(BaseHandler):
     def get(self):
        configid= None
        configid = self.get_cookie("configid")
        print configid

But this is not working. When I print the id -its getting displayed as None.

So basically I am not able to pull the value of the id which is a link, and the id is basically coming from the database Please help me out. Is my approach correct?

Thanks in Advance

解决方案

Where is the database here? since you use id why not accessing a database, say, MongoDB.

You have to know, that the cookie will be sent and received with your http messages, so you have to be aware of that, unless you want to make a local storage, but here, you have to garantee that, your users use an HTML5 browser, and send the data for the first time to be stored at the client end.

So the approache i suggest, is using the database, and use a hidden <input> and the value is the id.

这篇关于获取动态锚定标记的值并将其传递到下一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆