在jQuery中向对象数组添加函数

时间:2014-12-21 18:14:42

标签: jquery

我正在努力建立这个:

var words = [
  {text: "Lorem", weight: 13, handlers: {
    click: function() {
      alert('You clicked the word !');
    }
  }},
  {text: "Ipsum", weight: 10.5},
  {text: "Dolor", weight: 9.4},
  /* ... */
];

我正在用“text”和“weight”构建单词数组,用.each解析xml并使用:

   var text = $(this).find("text").text();
   var weight = $(this).find("weight").text();

   word = {
         text: text,
         weight: weight
           }

   keywords.push(word);

但是如何在上面的代码中添加处理程序的属性?

0 个答案:

没有答案