使用复选框选择从商店中删除记录

时间:2016-04-26 12:55:44

标签: php sql extjs

我有这个ajax请求,它遍历商店并删除所有选定的记录。

    Ext.Ajax.request({
    url: 'system/index.php',
    method: 'POST',
    params: {
        class: 'LicenseFeatures',
        method: 'delete',
        data: Ext.encode({
        feature_id: ( function(){
                var e = "";
                var sel = Ext.getCmp('featureGrid').getSelection();
                var c = 0;
                for( var i in sel ) {
                    var x = ( c == 0 ) ?  e = sel[i].data.feature_id : e += "," + sel[i].data.feature_id;
                    c++;
                }
                return e;
            })()
    })

},
                 success: function( response ){
    Ext.MessageBox.alert( 'Status', 'Record(s) has been deleted.' );
    Ext.getStore('LicenseFeaturesStore').reload();
},
    failure: function(){
        Ext.MessageBox.alert( 'Status', 'Failed to delete records.' );
    }
});

目前,代码从网格中检索1个id并删除它。我需要做的是从网格中获取两个Id,因为我需要将特定的sql运行到数据库。 sql需要两个输入,这里是sql

public function delete( $vars ){
$sql = "DELETE FROM `LicenseFeatures` WHERE feature_id in({$vars->data->feature_id}) AND license_id in({$vars->data->license_id})";
if( $result = $vars->db->query( $sql ) ) {
    echo json_encode( array( "success" => true,"sql"=>$sql ) );
} else {
    echo json_encode( array( "success" => false ) );
}
}

1 个答案:

答案 0 :(得分:0)

尝试将data属性更改为此。

data: Ext.encode(( function(){
    var feature_id,
        licence_id;
    var sel = Ext.getCmp('featureGrid').getSelection();
    var c = 0;
    for( var i in sel ) {
        if (c == 0) {
            feature_id = sel[i].data.feature_id;
            licence_id = sel[i].data.licence_id;
        } else {
            feature_id += "," + sel[i].data.feature_id;
            licence_id += "," + sel[i].data.licence_id;
        }
        c++;
    }
    return {
        feature_id: feature_id,
        licence_id: licence_id
    };
})())
相关问题