尝试使用 id==valores0 注册小部件,但该 id 已注册

2023-12-29

我收到此错误,我不知道如何解决。我读这个链接 https://stackoverflow.com/questions/2222517/error-tried-to-register-widget-with-id-grid1but-that-id-is-already-registered before.

EDIT:1

索引.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

<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>

问题:第一次单击提交按钮一切正常,导入了 5 个滑块。第二次单击,应该进行更新,但我收到此消息:

Tried to register widget with id==valores0 but that id is already registered

[演示视频]2 http://www.youtube.com/watch?v=paj_TUu7yO4


只是添加@missingo 的答案和@Kevin 的评论。您可以通过查看注册表来浏览现有的 dijit:

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.
*/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试使用 id==valores0 注册小部件,但该 id 已注册 的相关文章

随机推荐