私はdojoを使用してプログラムでdom要素を作成していますが、idでDOM内にDOM要素を表示できますが、dom.byId( "myId ")はnullを返します。dojoを使用するdom.byIdはプログラムで要素を追加していません
私は実際に働いているので(私の問題を再現しませんが、私が何をしようとしているのかが分かります):ボタンをクリックすると(スタイリングの不足は無視されます)実行出力パネルで、dom.byIdによって取り出された要素の内容を警告します。しかし、私のdojoウィジェット内の同様のコードは機能しません。ここでは、コードです:
var content = lang.replace(selectFilterTemplate, {
"layer-id": layer.id,
"layer-index": idx,
"filter-name": filter.name
}); // this gets template HTML code similar to what's in the HTML panel of the jsfiddle, only it has placeholder tags {} instead of literals, and the tags are replaced with the attributes of the layer, idx, and filter objects here
// Use dojo dom-construct to create a div with the HTML from above
var node = domConstruct.create("div", { "innerHTML": content });
// put the new div into a dojo ContentPane
var filterPanel = new ContentPane({
"id": layer.id + "-filter-" + idx + "-panel",
"content": node,
"style": "width: 200px; float: left;"
});
// Get the dom element:
var mstag = dom.byId(layer.id + "-filter-" + idx + "-ms-tag")
// this is the same as the "var ms = dom.byId("IssuePoints-filter-1-ms-tag")" in the jsfiddle, but this one returns null. If I view the contents of the 'node' variable in the browser debugging console at this point, I can see the <select> tag with the id I'm referencing.
私がデバッグコンソールでDOMにその要素を見ることができれば、なぜ私は私のdom.byId()でnullを取得するのでしょうか?
ありがとうpgianna。新しいContentPane()の終わりに.plactAt(document.body)を置くことは、私のためのトリックでした。 – user2193215