如何添加itemtap

时间:2011-06-13 23:01:48

标签: javascript sencha-touch

我有一个列表,我无法在列表中获取可点击的项目。我有onItemDisclosure,它应该可以工作,但事实并非如此。我希望整行可以点击,但我似乎无法得到任何工作。

    onItemDisclosure : function(record, btn, index) {
        //window.location = 'http://www.google.com';
    }

这是我的完整源代码

    Ext.ns("Course", "Course.stores");

Course = new Ext.Application({
  defaultTarget : 'viewport',
  name : 'Course',
  launch : function() {
    console.log('begin');

    this.viewport = new Ext.Panel({
      fullscreen : true,
      dockedItems : [ {
        title : 'Course Catalog',
        xtype : 'toolbar',
        ui : 'light',
        dock : 'top'
      } ],
      layout : 'fit',
      scroll : 'vertical',
      items : [ {
        xtype : 'list',
        itemTpl : '<span id="{letter}">{course}</span>',
        store : Course.stores.Properties,
        singleSelect : true,

        itemSelector : 'span.id',
        onItemDisclosure : function(record, btn, index) {
            //window.location = 'http://www.google.com';
        }
      } ],
      flex : 1
    });

  }
});

Ext.regModel('Properties', {
  fields : [ {
    name : 'letter',
    type : 'string'
  }, {
    name : 'course',
    type : 'string'
  } ]
});

Course.stores.Properties = new Ext.data.Store({
  model : 'Properties',  
  sorters: 'letter',
  getGroupString : function(record) {
        return record.get('letter')[0];
  },
  proxy : {
    type : 'ajax',
    url : '../lib/course_catalog.php',
    reader : {
      type : 'json',
    }
  },
  autoLoad : true
});

2 个答案:

答案 0 :(得分:2)

尝试这样的事情:

items : [ {
    xtype : 'list',
    itemTpl : '<span id="{letter}">{course}</span>',
    store : Course.stores.Properties,
    listeners: {
        scope : this,
        itemtap : function(foo, bar, etc) {
            doSomething...
        }
  } ],

答案 1 :(得分:0)

没有处理点击的原因是因为你覆盖了itemSelector配置:

itemSelector : 'span.id',

你不应该这样做,因为Ext.List希望它是一个特定的内部设置值,以便正确处理项目上的事件。只需从配置中删除它,就可以让它开始工作。