如何访问JSON对象属性
How to access JSON object properties
我无法访问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,
"answerswers": [],
"change": 'none'
}
},
addAnswer: function (a) {
answers.push(a);
},
getAnswer: function (idx) {
return this.answers[idx];
}
});
然后在我的代码中像这样创建它:var cq = new contractorTestQuestion(qid, q, m, t, tqQuesPos);
我要做的是cq。问题,并能够获得存储在该字段中的值。
我不知道我做错了什么
不能通过将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';
},
相关文章:
- jQuery匹配JSON对象的部分文本
- 如何在Javascript中将JSon对象转换为数组
- 我可以在json对象中添加一个函数吗
- 使用JS将数组转换为json对象
- 如何为json对象中的段发送array[]
- 将JSON对象传递给angular指令
- 更改JSON对象的结构
- 访问JSON对象内部的数组元素
- 在ejs-partial中对JSON对象进行迭代
- 遍历 JSON 对象并检查 URL 是否以某个值结尾
- 访问嵌套JSON对象的键,其中键是动态的
- json对象中缺少对象循环
- 发送json对象或使用express路由呈现视图
- 在play2框架中向json对象添加下拉列表项
- 元素名称上带有短划线 (-) 字符的 Json 对象
- autocomplete不接受源的json对象
- 如何在javascript中创建动态json对象
- 在使用客户端脚本时拾取JSON对象
- 如何通过json对象数组为嵌套对象赋值
- 构造JSON对象