在Extjs,我如何看到如果复选框被选中,然后如果它被选中,将复选框id添加到数组


In Extjs, How do I see if a checkbox is checked, and then if it is checked, add that checkboxes id to an array?

我正在学习Extjs以及PHP和MySQL为我的一个网络开发课程在大学现在,我非常接近完成我的期末项目为类,我被困在一些简单的东西作为一个复选框。我更喜欢c#编程,所以我的c#思维与ExtJS的必要性相冲突。

该程序向医院病人询问了大量关于他们日常感受的问题,我有一个常见症状的复选框列表,我需要能够查看,一旦他们提交表格,哪些症状被选中,并将该症状id添加到症状数组中。

这很接近吗?

    if(headacheCheckbox.getValue()==true){
        symptoms[headacheCheckbox.getId()];
    }

在服务器端我有

        $id=$dbh->lastInsertId();
        $symptom=$_REQUEST['symptoms'];
        while($tmp=$symptom->fetch()){
        $stmt=$dbh->prepare("insert into symptom_input (inputid, symptomid) values (?,?)");
        $stmt->bindParam(1, $id);
        $stmt->bindParam(2, $tmp);
        $stmt->execute();
        }

,我有我的ajax请求在我的ExtJS在症状数组作为一个参数,像这样…

    params: {action: 'create_input',
        symptoms: symptoms[],
        },

绝对欢迎任何帮助/批评。

谢谢!

这一行

 $symptom=$_REQUEST['symptoms'];

和这一行

 while($tmp=$symptom->fetch()){

不计算

fecth是为准备好的语句对象http://il2.php.net/manual/en/mysqli-stmt.fetch.php的方法(当你获取一个结果集,类似于mysql_fecth_row的未准备的语句),而你有一个数组解析到这个变量$symptom=$_REQUEST['symptoms'];,所以你的fetch将抛出一个错误,而

假设你的数组是这样的

$_REQUEST['symptoms'][112];
$_REQUEST['symptoms'][234];

你需要的是这样的东西

  $id=$dbh->lastInsertId();
  $symptom=$_REQUEST['symptoms'];
   foreach($symptoms as $symptomid){
        $stmt=$dbh->prepare("insert into symptom_input (inputid, symptomid) values (?,?)");
        $stmt->bindParam(1, $id);
        $stmt->bindParam(2, $symptomid);
        $stmt->execute();
        }

当传递参数

假设下面的代码是在JavaScript中创建一个数组

if(headacheCheckbox.getValue()==true){
        symptoms[headacheCheckbox.getId()];
    }

你需要

params: {action: 'create_input',
        symptoms: symptoms //without square brackets and no comma IE7 will throw an error
        },