[英]GoJS Diagram not loading at initial call
I have been trying to load a graph from a default selected value in a drop down list.我一直在尝试从下拉列表中的默认选定值加载图表。 This is the html for the select element.
这是选择元素的 html。
<select class="custom-select" id="activity">
<option disabled value="">Select an activity</option>
<option selected value="Running">Running</option>
</select>
And then the javascript goes like this.然后javascript是这样的。
function loop() {
setTimeout(function () {
load(activities.value);
loop();
}, 5000);
}
var activities = document.getElementById("activity");
load(activities.value);
I tried this and the graph just dows not not load up.我试过了,图表只是没有加载。 But then i tried this
但后来我尝试了这个
function loop() {
setTimeout(function () {
load(activities.value);
loop();
}, 5000);
}
var activities = document.getElementById("activity");
load(activities.value);
loop();
function load(activity){
graph= {"class": "go.GraphLinksModel",
"nodeDataArray": [{}],
"linkDataArray": [{}]
}
myDiagram.model = go.Model.fromJson(graph);
}
And the initial function call just before loop() does not load the graph.并且 loop() 之前的初始函数调用不会加载图形。 But after 5 seconds once the loop kicks in the graph loads up .
但是 5 秒后,一旦循环在图表中启动,就会加载。 And every 5 seconds it keeps loading up just like it should.
并且每 5 秒它就会像它应该的那样继续加载。 I also tried adding a onchange event listener to the drop down with 2 more options and added.
我还尝试在下拉菜单中添加一个 onchange 事件侦听器,并添加了另外 2 个选项。
activities.addEventListener("change", () => {
load(activities.value);});
and once i changed back and forth the graphs load up.一旦我来回更改,图表就会加载。
I also tried the myDiagram.requestUpdate();
我还尝试了
myDiagram.requestUpdate();
right after the load(activities.value);
load(activities.value);
. .
Where an going wrong?哪里出错了? What am i doing wrong?.
我究竟做错了什么?。 Appreciate all advices and questions for any more clarification and ofcourse some answers if anyone can help.
感谢所有建议和问题以获得更多澄清,当然还有一些答案,如果有人可以提供帮助。
I found the solution to be the problem to be the load function initially being called before the div element is available.我发现解决方案是在 div 元素可用之前最初调用加载函数的问题。 After adding a
window.addEventListener('DOMContentLoaded', init);
添加后
window.addEventListener('DOMContentLoaded', init);
it is working fine now.现在工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.