i get this error, and i don't know how can be solved. I read this link before.
我得到这个错误,我不知道如何解决。我以前读过这个链接。
EDIT:1
编辑:1
index.php
index . php
<script type="text/javascript">
$(document).ready(function() {
$("#customForm").submit(function() {
var formdata = $("#customForm").serializeArray();
$.ajax({
url: "sent.php",
type: "post",
dataType: "json",
data: formdata,
success: function(data) {
switch (data.livre) {
case 'tags':
$("#msgbox2").fadeTo(200, 0.1, function() {
$(this).html('Empty tags').fadeTo(900, 1);
});
break;
default:
$("#msgbox2").fadeTo(200, 0.1, function() {
$(this).html('Update').fadeTo(900, 1, function() {
$('#conteudo').load('dojo/test_Slider.php');
});
});
break;
}
}
});
return false;
});
});
</script>
test_slider.php
test_slider.php
<script type="text/javascript">
var slider = [];
for (i = 0; i < 5; i++) {
slider[i] = (
function(i) {
return function() {
var node = dojo.byId("input"+[i]);
var n = dojo.byId("valores"+[i]);
var rulesNode = document.createElement('div'+[i]);
node.appendChild(rulesNode);
var sliderRules = new dijit.form.HorizontalRule({
count:11,
style:{height:"4px"}
},rulesNode);
var labels = new dijit.form.HorizontalRuleLabels({
style:{height:"1em",fontSize:"75%"},
},n);
var theSlider = new dijit.form.HorizontalSlider({
value:5,
onChange: function(){
console.log(arguments);
},
name:"input"+[i],
onChange:function(val){ dojo.byId('value'+[i]).value = dojo.number.format(1/val,{places:4})},
style:{height:"165px"},
minimum:1,
maximum:9,
}
},node);
theSlider.startup();
sliderRules.startup();
}
})(i);
dojo.addOnLoad(slider[i]);
}
</script>
Problem: First click in submit btn all works well, 5 sliders are imported. Second click, an update is supposed, but i get this message:
问题:首先点击提交btn所有工作良好,5滑块被导入。第二次点击,应该是更新,但是我得到了这样的信息:
Tried to register widget with id==valores0 but that id is already registered
[Demo video]2
(演示视频)2
4 个解决方案
#1
3
Just to add on to @missingo's answer and @Kevin's comment. You could walk through the existing dijits by looking in the registry:
再加上@missingo和@Kevin的评论。你可以在登记处查阅现有的资料:
var i = i || 0; // Cache this at the end of your loop
dijit.registry.map(function (widget) {
if (+widget.id.replace(/^[^\d]+/, '') < i) {
widget.destroyRecursive();
}
});
/*
Your loop fixed as described in missingno's answer.
*/
#2
1
You fell in the age-old trap of making function closures inside a for loop. By the time addOnLoad fires and the sliders are created, i
will be equal to 2 and both sliders will try to use the same DOM nodes (something that is not allowed).
您陷入了一个由来已久的陷阱,即在for循环中创建函数闭包。当addOnLoad触发并创建滑块时,i将等于2,两个滑块将尝试使用相同的DOM节点(这是不允许的)。
You need to make sure that you give a fresh copy of i
for everyone. The following is a quick fix:
你需要确保你给每个人一份新的i。以下是一个快速解决方案:
for(i=0; i<2; i++){
(function(i){
slider[i] = ...
//everything inside here remains the same
//except that they now use their own i from the wrapper function
//instead of sharing the i from outside.
}(i));
}
#3
1
Dijit stores all active widgets in the dijit.registry, and uses id's as unique qualifiers. You can't create dijits with same id.
Dijit在Dijit中存储所有活动小部件。注册,并使用id作为唯一限定符。不能用相同的id创建dijits。
Need to clean dojo.registry before create a new slider dijits. Add this code before declare dijit on test_slider.php
需要清洁的dojo。在创建一个新的滑动条之前注册。在test_slider.php上声明dijit之前添加此代码
dijit.registry["input"+ [i]].destroyRecursive();
#4
0
can you assign any number ID like ID generated by 10 digit random number or something with datetime combination so id will never be same.
你能分配任意数字ID,比如由10位随机数生成的ID,或者具有datetime组合的ID吗?
#1
3
Just to add on to @missingo's answer and @Kevin's comment. You could walk through the existing dijits by looking in the registry:
再加上@missingo和@Kevin的评论。你可以在登记处查阅现有的资料:
var i = i || 0; // Cache this at the end of your loop
dijit.registry.map(function (widget) {
if (+widget.id.replace(/^[^\d]+/, '') < i) {
widget.destroyRecursive();
}
});
/*
Your loop fixed as described in missingno's answer.
*/
#2
1
You fell in the age-old trap of making function closures inside a for loop. By the time addOnLoad fires and the sliders are created, i
will be equal to 2 and both sliders will try to use the same DOM nodes (something that is not allowed).
您陷入了一个由来已久的陷阱,即在for循环中创建函数闭包。当addOnLoad触发并创建滑块时,i将等于2,两个滑块将尝试使用相同的DOM节点(这是不允许的)。
You need to make sure that you give a fresh copy of i
for everyone. The following is a quick fix:
你需要确保你给每个人一份新的i。以下是一个快速解决方案:
for(i=0; i<2; i++){
(function(i){
slider[i] = ...
//everything inside here remains the same
//except that they now use their own i from the wrapper function
//instead of sharing the i from outside.
}(i));
}
#3
1
Dijit stores all active widgets in the dijit.registry, and uses id's as unique qualifiers. You can't create dijits with same id.
Dijit在Dijit中存储所有活动小部件。注册,并使用id作为唯一限定符。不能用相同的id创建dijits。
Need to clean dojo.registry before create a new slider dijits. Add this code before declare dijit on test_slider.php
需要清洁的dojo。在创建一个新的滑动条之前注册。在test_slider.php上声明dijit之前添加此代码
dijit.registry["input"+ [i]].destroyRecursive();
#4
0
can you assign any number ID like ID generated by 10 digit random number or something with datetime combination so id will never be same.
你能分配任意数字ID,比如由10位随机数生成的ID,或者具有datetime组合的ID吗?