js获取当前选择的对象

function show_modal3(thisobj) {
    var data = $table.bootstrapTable('getData');
    var index = $(thisobj).parent("li").parent("ul").parent("div").parent("button").parent("td").parent("tr").data('index');
    console.log("当前索引:"+index);
    var dict=data[index];
    var key="title";
    if(dict.hasOwnProperty(key)){
        var old_title=dict[key];
        console.log("标题为:"+old_title);
    }
    $("#old_title").val(old_title);
    $("#title_index").val(index);

    $('#myModal3').modal('show');
}
function capitalize(str) {
    if(true){
        var array = str.toLowerCase().split(" ");
        for (var i = 0; i < array.length; i++) {
            array[i] = array[i][0].toUpperCase() + array[i].substring(1, array[i].length);

            //array[i][0] = array[i][0] + 'A' - 'a';
        }
        var string = array.join(" ");

        return string;
    }

}

$(function () {
    $("#update_title").click(function () {
        var new_title = $('#old_title').val();
        // console.log(new_title);
        new_title=capitalize(new_title);
        console.log(new_title);
        var title_index=$('#title_index').val();
        var data = $table.bootstrapTable('getData');
        var dict=data[title_index];
        if(dict.hasOwnProperty("title")){
            var old_title=dict["title"];
        }
        console.log(old_title)
        if (!new_title) {
            return 'This field is required';
            //为空无法关闭 输入文字才消失
        }else if(old_title==new_title){
            $('#myModal3').modal('hide');
        }else{
            if(dict.hasOwnProperty("product_id")){
                var product_id=dict["product_id"];
            }
            if(dict.hasOwnProperty("sku")){
                var sku=dict["sku"];
            }
            if(dict.hasOwnProperty("upload_user_id")){
                var user_id=dict["upload_user_id"];
                if(user_id==null){
                    if(dict.hasOwnProperty("store_id")){
                        user_id=dict["store_id"];
                    }
                }
            }
            $.ajax({
                type:"POST",
                dataType:"json",
                url:'/update_title/',
                data: {
                    "csrfmiddlewaretoken":document.getElementsByName('csrfmiddlewaretoken')[0].value,
                    "product_id":product_id,
                    "sku":sku,
                    "name":"title",
                    "old":old_title,
                    "new":new_title,
                    "userId":user_id,
            },
            success:function () {
                $('#myModal3').modal('hide');
            },error:function () {
                $('#myModal3').modal('hide');
            },
            // complete:function () {
            //     $('#myModal3').modal('hide');
            // }
        })
        }


    });

});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值