我在Jquery见过的最奇怪的事

时间:2018-04-26 08:49:39

标签: javascript jquery

我正在使用jquery流程图https://github.com/sdrdis/jquery.flowchart

如果我动态创建对象,它不会生成任何图表(意味着$('#testCaseConnections').flowchart没有做任何事情,但也没有给出任何错误。)

但是,如果我从Chrome开发工具中复制该对象,并说var flowData =我复制的那个对象有效。

到底是什么?为什么呢?

var flowData = {};
                    var operators = {};
                    var data = ["FIRST","SECOND"];
                    
                      $.each(data, function (index, value) {
                      
                      var operator = {};
                        $.ajax({
                            type: 'post',
                            url: '/flow/getInputs?testCaseName=' + value,
                            success: function (inputs) {
                                //Create test case container
                                var properties = {};
                                properties["title"] = testCaseName;
                                var operatorInputs = {};
                                for (var i = 0; i < inputs.length; i++) {
                                    operatorInputs["input_" + i] = {
                                        label: inputs[i].name
                                    };
                                }
                                properties["inputs"] = operatorInputs;
                                properties["outputs"] = {};
                                operator = {
                                    top: 80,
                                    left: 300
                                };
                                operator["properties"] = properties;
                                operators["operator" + index] = operator;
                            }
                        });
                    });

                    flowData["operators"] = operators;
                    console.log(flowData);

 // Apply the plugin on a standard, empty div...
                $('#testCaseConnections').flowchart({
                    data: flowData
                });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

0 个答案:

没有答案