2012-03-31 29 views
0

我建立我自己的小部件道场如这里讨论:Custom Widget后JSON数据

现在,我想用下面的代码张贴在特定事件中的数据:

xhr.post({ 
    handleAs: "json", 
    form: "answerForm", 
    timeout: 15000, 
    load: lang.hitch(this, "_onSubmitted", button), 
    error: lang.hitch(this, "_onSubmitError", button) 
}); 

我希望这样的事情在我xhr.post content: dojo.toJson(this)

我怎么能发送JSON格式的数据到服务器? 谢谢!

编辑:加入HTML模板

<form id="answerForm" action="${url}"> 
    <div data-dojo-attach-point="selectionAnswerWidget" data-dojo-type="dijit.layout.ContentPane" 
     data-dojo-props="region: 'bottom'"> 

     <div data-dojo-type="dojo.store.Memory" data-dojo-id="answerStore" 
      data-dojo-props="data: [{id: 'YES', name: 'yes'}, {id: 'NO', name: 'no'}, {id: 'UNANSWERED', name: 'unanswered'}]"></div> 
     <input data-dojo-type="dijit.form.FilteringSelect" value="${answer}" 
      data-dojo-props="store:answerStore, searchAttr:'name'" data-dojo-attach-point="answerSelection" /> 
    </div> 

    <div data-dojo-attach-point="textAreaAnswerWidget" data-dojo-type="dijit.layout.ContentPane" 
     data-dojo-props="region: 'top'"> 

     <textarea data-dojo-attach-point="commentNode" rows="5" cols="50" data-dojo-type="dijit.form.SimpleTextarea" 
      data-dojo-props="selectOnClick:true">${comment}</textarea> 
    </div> 

的数据是正确的HTML和后到达服务器,但没有数据。

+0

我纠正了我的'data-dojo-attach-point' – myborobudur 2012-04-03 07:02:25

回答

1

在你的xhrArgs中使用postData。

xhr.post({ 
handleAs: "json", 
postData: dojo.toJson(obj), 
timeout: 15000, 
load: lang.hitch(this, "_onSubmitted", button), 
error: lang.hitch(this, "_onSubmitError", button) 
}); 
+0

与postData我将不得不重新创建与我加载我的小部件相同的对象。你知道为什么'form:“answerForm”'不起作用。数据在那里 – myborobudur 2012-03-31 14:47:17

+1

我的答案的重点可能不正确。你的问题是,当你发布时,你的widget的数据不在post参数中?您的自定义小部件是否有html输入字段?发布表单,将查找数据的html输入字段。 – 2012-03-31 17:06:07

+0

我添加了html模板(参见上文)。是的,帖子中没有数据 – myborobudur 2012-03-31 17:11:58