2012-03-31 32 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