2011-10-10 162 views
0

我无法访问我的JSON对象属性。鉴于此构造如何访问JSON对象属性

contractorTestQuestion = function (id, question, multianswer, textanswer, order) { 
    var cntrQuestion; 
    this.initialize(id, question, multianswer, textanswer, order); 
} 

$.extend(contractorTestQuestion.prototype, { 
    initialize: function (_i, _q, _m, _t, _o) { 
      cntrQuestion = { 
      "questid" : _i, 
      "question": _q, 
      "multianswer": _m, 
      "textanswer": _t, 
      "order": _o, 
      "answers": [], 
      "change": 'none' 
     } 
    }, 
    addAnswer: function (a) { 
     answers.push(a); 
    }, 
    getAnswer: function (idx) { 
     return this.answers[idx]; 
    } 
}); 

然后我在我的代码是这样创造的: VAR CQ =新contractorTestQuestion(QID,Q,M,T,tqQuesPos);

我想要做的是cq.question,并能够获得存储在该字段中的值。

我想不通,我将它添加到一个私有变量做错了什么

+0

是我看到正在使用的jQuery的扩展方法?可能也想用jquery来标记问题。 –

+0

我看到的是JSON吗? Err,[no](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/)。可能要删除对它的引用。 – Quentin

回答

2

你不能只是设置的contractorTestQuestion属性。

坐落在this的性能,如:

initialize: function (_i, _q, _m, _t, _o) { 
    this.questid = _i; 
    this.question = _q; 
    this.multianswer = _m; 
    this.textanswer = _t; 
    this.order = _o; 
    this.answers = []; 
    this.change = 'none'; 
}, 

而且,这有没有关系JSON这是一种数据格式。

+0

谢谢,我仍然处于这种学习曲线的优势。 – edepperson