在 ExtJS 中,我可以在 Ajax 请求中调用 for 循环和 if 语句来定义参数吗?
我正在尝试迭代 fieldSet 中的复选框,如果选中了该复选框,我想将该复选框的 id 添加到一个数组中,该数组将作为 Ajax 请求的参数之一。
我意识到我可以创建一个 Checkbox 组,但我是 ExtJS 的新手,直到创建每个单独的复选框后才发现 Checkboxgroup。
到目前为止我有这个..
function submitEntry(){
Ext.Ajax.request({
url: '../../inc/project4.php',
var obj = Ext.select('input[type=checkbox]').elements;
var i = 0;
for (i=0; i<obj.length; i++) {
if (obj[i].checked) {
params:{
symptom[]: obj[i].getId()
}
}
}
params: {action: 'create_input',
description: entryBox.getRawValue(),
},
method: 'POST',
success: function(f,a){
var jsonData = Ext.util.JSON.decode(f.responseText);
if(jsonData.success == true){
Ext.Msg.alert("Success!", "Your journal entry has been sent!");
entryStore.reload();
entryBox.reset();
}
else{
Ext.Msg.alert("Error! Please check your entry and try again.")
}
},
failure: function(f,a){
if(jsonData.success == false){
Ext.Msg.alert("Error! Please check your entry and try again.");
}
}
});
}
请挑选并指出任何错误。我不确定我有两个参数部分的方式是否有效。我只需要将选中的复选框的 id 添加到数组中,并将该数组作为我的参数之一发送。
预先非常感谢您的帮助!
I am trying to iterate through my checkboxes that are in a fieldSet and if the checkbox is checked, I would like to add the id of the checkbox to an array that would be one of my parameters for my Ajax request.
I realize that I could have created a Checkbox group, but I am new to ExtJS and didn't find out about Checkboxgroup until after I created each individual checkbox.
So far I have this..
function submitEntry(){
Ext.Ajax.request({
url: '../../inc/project4.php',
var obj = Ext.select('input[type=checkbox]').elements;
var i = 0;
for (i=0; i<obj.length; i++) {
if (obj[i].checked) {
params:{
symptom[]: obj[i].getId()
}
}
}
params: {action: 'create_input',
description: entryBox.getRawValue(),
},
method: 'POST',
success: function(f,a){
var jsonData = Ext.util.JSON.decode(f.responseText);
if(jsonData.success == true){
Ext.Msg.alert("Success!", "Your journal entry has been sent!");
entryStore.reload();
entryBox.reset();
}
else{
Ext.Msg.alert("Error! Please check your entry and try again.")
}
},
failure: function(f,a){
if(jsonData.success == false){
Ext.Msg.alert("Error! Please check your entry and try again.");
}
}
});
}
Please pick and point out any errors. I am unsure if the way I have two sections for params will even work. I just need to add the id's of the checked checkboxes to the array and send that array as one of my parameters.
Thank you very much in advance for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要多个表达式来收集复选框,则应该在调用 Ext.Ajax.request 之前收集它们。
If you need more than one expression to collect your checkboxes, you should collect them before the call to Ext.Ajax.request.