div.someclass
가 존재하지 않는 경우 자동으로 생성되도록 다음 코드를 확장하는 간단한 방법이 있습니까?D3JS 선택 및 등급
d3.select("body").select("div.someclass").selectAll("p")
.data([ 1, 2, 3 ])
.enter()
.append("p")
.text(function (d, i) {
return "index: " + i + ", value: " + d;
});
저는 아직 D3JS를 배우는 초기 단계에 있습니다. 지금까지의 나의 이해는 "D3에게 무언가를하는 방법을 말하는 대신에, D3에게 당신이 원하는 것을 말하라"는 것입니다. 그래서 위의 코드는 <div class="someclass"></div>
이 HTML로 선언되어야한다는 것을 알게되어 놀랐습니다.
/** Append HTML placeholder programmatically **/
placeholder = d3.select("body").append("div").attr("class", "someclass");
/** Bind the data to the DOM **/
/** instead of telling D3 how to do something, tell D3 what you want: in the absence of <p>, this will return a virtual selection **/
placeholder.selectAll("p")
.data([ 1, 2, 3 ])
.enter()
.append("p")
.text(function (d, i) {
return "index: " + i + ", value: " + d;
});
짧은/더 나은 방법이 있나요 :
대안은 프로그래밍 사업부를 삽입하는 것입니다?
그게 내가 원하는 부분 이었어. 고마워. –