扩展对象';s参数Javascript(Coffeescript代码)
我有以下代码:扩展对象';s参数Javascript(Coffeescript代码),javascript,object,coffeescript,Javascript,Object,Coffeescript,我有以下代码: tickets = new Object() $(this).parents('.request-form').find('.Single').each -> if $(this).find('.checkBoxParent input').prop('checked') params = new Object() params.sarId = $(this).parents('.request-form').find('.sarId
tickets = new Object()
$(this).parents('.request-form').find('.Single').each ->
if $(this).find('.checkBoxParent input').prop('checked')
params = new Object()
params.sarId = $(this).parents('.request-form').find('.sarId').text()
params.comments = $(this).find('.commentBoxParent textarea').val()
params.serviceId = $(this).find('.serviceId').text()
tickets[$(this).parents('.categoryQuestions').find('.form-label').text()] = params
其思想是票证将保持为空,但当它浏览html时,它将向其中添加项目和子项目列表
例如,它可以找到标签“教室”和表单该部分的3个参数
因此,我希望对象看起来像:
tickets[教室][{sarId:1,serviceId:3,注释:“hi”}]
然后,它可以找到另一个“教室”标签,我希望它附加,这样对象现在看起来像:
tickets[课堂][{sarId:1,serviceId:3,注释:“你好”},{sarId:1,serviceId:6,注释:“另一条注释”}]
我怎样才能做到这一点 将其切换到多维数组/对象的工作方式如下:
requestForm = $(this).parents('.request-form');
tickets = {}
requestForm.find('.Single').each ->
#alert("this should happen... 4 times")
focus = $(this)
if $(this).find('.checkBoxParent input').prop('checked')
label = $(this).parents('.categoryQuestions').find('.form-label').text()
if (!tickets.hasOwnProperty(label))
tickets[label] = []
tickets[label].push({
sarId: requestForm.find('.sarId').text(),
comments: $(this).find('.commentBoxParent textarea').val(),
serviceId: $(this).find('.serviceId').text()
})
不能将对象用作属性键。你到底想要什么?