动态分配ID [英] Dynamically assign ID
问题描述
我正在使用nodejs和expressjs.
I am using nodejs and expressjs.
我从数据库加载列表.选择任何列表元素都会弹出一个覆盖图,用于编辑和删除所选项目.我不知道如何将所选列表项发送到快递路线.
I load a list from a database. Selecting any of the list elements bring up an overlay with to EDIT and DELETE the selected item. I can not figure out how to send the selected list item to the express route.
我认为需要完成的工作:动态地向叠加层上的按钮分配一个ID.我试图做一个小提琴,但覆盖无法正常工作.
What I believe needs to be done: Dynamically assign an ID to the buttons on the overlay. I tried to make a jfiddle but the overlay would not work.
有什么想法吗?我正在使用jquery将叠加层滑入视图.
Any ideas? I am sliding the overlay into view with jquery.
感谢您抽出宝贵的时间阅读此书
Thank you for taking the time to read this
我有一个动态创建的列表,每个项目都带有".recordlongpress"类,并且将其Jquery功能应用于其上.
I have a dynamically created list, each item with the class ".recordlongpress" and I apply this Jquery functionality to it.
$(document).ready(function(){
$('.recordlongpress').bind('tap', function() {
return;
});
$('.recordlongpress').bind('taphold', function() {
$('#overlay').fadeIn('fast',function(){
$('#box').animate({'top':'100px'},500);
});
});
$('#boxclose').click(function(){
$('#box').animate({'top':'-100px'},500,function(){
$('#overlay').fadeOut('fast');
});
});
});
哪个显示了我的叠加层,这是通过CSS和此HTML的组合完成的
Which brings up my overlay which is done by a combination of CSS and this HTML
<div class="overlay" id="overlay" style="display:none;"></div>
<div class="box" id="box">
<a class="boxclose" id="boxclose"></a>
<button onclick="location.href='/scape/editcustomerform/id'">Edit Contact</button>
<button onclick="location.href='/scape/deletecustomer/ID'">Delete Contact</button>
<button>E-mail Customer</button>
<button>Call Customer</button>
<button>GPS to Address</button>
<button>Create Quote</button>
<button>Create Sales Order</button>
<button>Create Cash Sale</button>
</div>
</div>
我尝试将路径ID附加到我的路线的末尾,但实际上只是使用单词ID.谢谢您的帮助
I have tried to append the path id to the end of my route, but it just literally takes the word id. Thank you for any help
推荐答案
尝试一下:
var box = document.getElementById('box'),
buttons = box.getElementsByTagName('button');
for(var i = 0; i < buttons.length; i++){
buttons[i].id = [ 'my', 'button', 'id', i ].join('-');
}
此外,您可以尝试映射"操作:
Also, you may try to "map" actions:
var box = document.getElementById('box'),
buttons = box.getElementsByTagName('button');
var map = [
'editcustomerform',
'deletecustomer',
'emailcustomer',
'callcustomer',
'gpstocustomer',
'createquote',
'createsalesorder',
'createcashsale'
];
for(var i = 0; i < buttons.length; i++){
buttons[i].id = [ 'my', 'button', 'id', i ].join('-');
buttons[i].onclick = function(){ location.href = [ '/scape', map[i], 'id' ].join('/'); }
}
这篇关于动态分配ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!