私の Web アプリは、SQL データベースから情報を取得し、その情報に基づいてオブジェクトを作成できる必要があります。これらは、クリック イベント (およびそれらに関連付けられたその他のメソッド) を必要とする HTML 要素です。
私が現在していること:
function init() {
//initially creates objects based on SQL database
//user creates a new Foo
fooA = new Foo({id: i, otherInfo: "..."});
$(fooA.selector).click({...});
$(fooA.selector).draggable({...});
//etc.
$(fooA.selector).appendTo('#topContainer');
function Foo(data) {
this.id = data.id;
this.html = "";
this.selector = "#"+this.id;
$('<div/>',{
"class": "Foo",
id: this.id,
text: 'Blah blah blah'
})
}
更新: イベントを持つ HTML div を作成するより良い方法はありますか、それとも効率的で適切な方法ですか? また、JavaScript オブジェクトを配列に作成する必要がありますか?