0

下面是我尝试添加 onclick 函数的代码示例,但它似乎没有按预期工作。目的是获取 div 标记文本值并将其放入变量中或通过 myFunction 之类的函数返回它我也尝试添加侦听器,但不知道它是如何工作的。作为一个模板,它很难调试。并且 onclick 事件或调用层次结构不容易找到。如何用简单的javascript解决它?

var resultTmpl = '<div id="group_header_{locationName}" class="current_list_audit_location expcol_{locationName:removeSpaces}" style="display:none;">'+
            '<tpl for="pickslipid">' +
         '<div class="audit_stage_list" style="margin-top: 6px !important;">' +
         '<div class="orderpickingpicklistimageurlStage margin-top"></div>' +
         '<div style="float:left;">' +
         '<div class="orderpickingpicklistStagedesc orderpickingpicklistStagedesc2" id={pickupSlipId} onclick="myfunction()" > {pickupSlipId}</div></div>' +
         '<div class="order_pick_right_stage_count_main_group_list audit_stage_pickup_date_list">' +
         '<div>Pickup Date: {pickupDate}</div>' +
         '</div>' +
         '</div>' +
         '</tpl>';

        // pass the root node of the data object

        Ext.define('sif.view.mapping.templates.EX04AuditStagingTpl', {
                extend: "Ext.XTemplate",
                html: resultTmpl,
                myfunction : function(){
                    return document.getElementByClass("orderpickingpicklistStagedesc orderpickingpicklistStagedesc2").value;
                },
                constructor: function() {
                    console.log(resultTmpl);
                    return this.callParent([this.html]);
                }
            });

            Ext.util.Format.removeSpaces = function(value) {
                  return !value ? value : String(value).replaceAll(" ", "_");
                };
            String.prototype.replaceAll = function(search, replacement) {
                    var target = this;
                    return target.split(search).join(replacement);
            };

上面的代码是从另一个类 EX04AuditStagingLocation 调用的,如下所示:

var ex04AuditStagingList = Ext.create('sif.view.mapping.templates.EX04AuditStagingTpl');
    var ex04AuditStageItems = {
        xtype: 'panel',
        width: '100%',
        height: '100%',
        cls: 'my-panel',
        ui: 'plain',
        itemId: 'ex04showdetailspanel',
        layout: {
            align: 'stretch',
            type: 'vbox'
        },
        items: [{
            xtype: 'list',
            cls: 'current_page_cycle_count',
            store: 'AuditStagingStore',
            itemTpl: ex04AuditStagingList,
            itemHeight: '100%',
            height: '100%',
            emptyText: '<p id="empty-text" style="text-align:center; left: 25px;">' + PhoneTopUtil.getLocaleString(1280040) + '</p>',
            grouped: true,
            zIndex: 10,
            pinHeaders: true,
            style: 'font-family: RobotoRegular;',
            loadingText: "",
            itemId: 'ex04AuditStageList',
            id: 'ex04AuditStageList',
            listeners: {
                painted: function(element, ths) {
                    SifUtils.customImageLoad(element.select('img').elements, 0, IMAGELOADING.CONFIRMPICKUP);
                },
                refresh: function(element, options) {
                    SifUtils.customImageLoad(element.element.select('img').elements, 0, IMAGELOADING.CONFIRMPICKUP);
                },
                itemtap: function(list, index, target, record) {
                    AuditOrMoveUtil.controller.onAmMoveAction(list, null, null, record);
                },
            }
        }
4

0 回答 0