开发者

How to access JSON object properties

I cannot access my JSON object properties. Given this constructor

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

$.extend(contractorTestQuestion.prototype, {
    initialize: function (_i, _q, _m,开发者_JAVA百科 _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];
    }
});

I then create it in my code like this: var cq = new contractorTestQuestion(qid, q, m, t, tqQuesPos);

what I want to do is cq.question and be able to get the value stored in that field.

I cannot figure out what I'm doing wrong


You cannot just set the properties of contractorTestQuestion by adding it to a private variable.

Set the properties on this like:

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';
},

Also, this has nothing to do with JSON which is a data format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜