我如何获得元素的data-id?

时间:2017-04-10 15:45:29

标签: javascript html

我想获取弹出窗口中所选元素的数据ID。  我必须在网格中显示您选择的解决方案。但对于数据库存储,我需要选择的ID值...我如何获取并绑定网格中的ID。

<script type="text/javascript">
        $(function () {
            // declaration
            $("#lognForm").ejDialog(
                {
                    enableModal: true,
                    enableResize: false,
                    width: 291,
                    close: "onDialogClose",
                    containment: ".cols-sample-area",
                    showFooter: true,
                    footerTemplateId: "sample"
                });
          $("#defaultlistbox").ejListView({ dataSource:ej.DataManager({
                url: "http://js.syncfusion.com/ejServices/Wcf/Northwind.svc/", crossDomain: true
            }),
			query: ej.Query().from("Suppliers").select("SupplierID", "ContactName"),
			fieldSettings: { text: "ContactName"},mouseUp: "onmouseup",height:"400px" ,enableCheckMark: true,
            enableFiltering: true,			
		
			});

            $("#btnOpen").ejButton({ size: "medium", "click": "onOpen", type: "button", height: 30, width: 172 });
            $("#Grid").ejGrid({
                columns: [
                        { field: "title", headerText: "ListviewData", width: 80 },
                ]
            });
            $("#btn1").ejButton({ size: "medium", "click": "onbtnOpen", type: "button", height: 30, width: 172 });

        });


        function onOpen() {
            $("#btnOpen").hide();
            $("#lognForm").ejDialog("open");          
        }
       function onbtnOpen(){
            $("#lognForm").ejDialog("close");
        }
        function onDialogClose(args) {
            $("#btnOpen").show();
        }

        function onmouseup(e) {
            var selections = $('#defaultlistbox').ejListView("getCheckedItems");
            var items = [];
            $(selections).each(function () {
                var $this = $(this);
                var item = { title: $this.find("span").html() };
    
            items.push(item);

            });
            if (selections.length > 0) {
                var obj = $("#Grid").ejGrid("instance");
                obj.setModel({ dataSource: items })
               obj.refreshContent(); 
        }  
      else{
         var obj = $("#Grid").ejGrid("instance"); 
        obj.dataSource([]);	}
    }

    </script>
<li class="e-user-select e-list e-list-check e-state-default" data-id="2">

1 个答案:

答案 0 :(得分:0)

如果您有对该javascript DOM对象的引用,只需查找dataset属性即可。它是一个包含字符串键的哈希映射,位于前缀为data的HTML元素上。 例如,您可以在对象上找到data-id myObject.dataset["id"]

相关问题