0

テーブルのコンテンツを埋めるオブジェクトの名前を保持する「recordsource」という名前のプロパティを持つテーブルがあります。

<table id="tbl" recordsource="myobj">

今ここに私の機能があります:

var myobj;

function obj()
{
  this.code = new Array();
  this.name = new Array();
}

myobj = new obj();
myobj.code = ["a","b","c"];
myobj.name = ["apple","banana","carrot"];

function populate_table()
{
  mytable = document.getElementById("tbl");
  mytableobj = mytable.getAttribute("recordsource"); //this will return a string
  //my problem is how to reference the recordsource to the myobj object that have
  //the a,b,c array
}
4

2 に答える 2

0

1 つの方法は、オブジェクトを、アクセスできるようにしたい他のすべてのオブジェクトのリストとして使用することです。

...

var obj_list = {
  'myobj': myobj
};

function populate_table()
{
  mytable = document.getElementById("tbl");
  mytableobj = mytable.getAttribute("recordsource");

  // Then obj_list[mytableobj] == myobj

  obj_list[mytableobj].code[0] // Gives "a"
  obj_list[mytableobj].name[0] // Gives "apple"
}
于 2012-07-12T02:46:20.353 に答える
0

window[ mytableobj ]これを試してみてくださいmyobj

于 2012-07-12T02:48:48.697 に答える