2012-07-16 100 views
0

嗨計算器社區,如何在Sencha Touch 2中創建搜索列表?商店已經定義

是的,我知道,其他人也有同樣的問題,但它們定義在同一個文件的存儲,煎茶觸摸我2個工程的例子,但是當我嘗試將此代碼來挖掘我得到這個錯誤:

Uncaught SyntaxError: Unexpected identifier Alertas.js:105 Uncaught Error: The following classes are not declared even if their files have been loaded: 'myMoney.view.Alertas'. Please check the source code of their corresponding files for possible typos: 'app/view/Alertas.js

我認爲我需要調用我店裏的另一種方式,但這裏是我的問題:

如何調用已經爲搜索列表中定義的店嗎?

有我的代碼:

Ext.define('myMoney.view.Alertas',{ 
extend: 'Ext.navigation.View', 
fullscreen: true, 
scrollable: true, 
styleHtmlContent: true, 
xtype: 'alertas', 

config: { 
    title: 'Contactos', 
    iconCls: 'bookmarks', 

    items: [ 
     { 
      xtype: 'list', 
      grouped: true, 
      ui: 'round', 
      title: 'Contactos', 
      fullscreen: true, 
      itemTpl: '{title}', 
      styleHtmlCls: true, 
      //cls: 'x-contacts', 
      store: 'Contactos', 
      itemTpl: [ 
       '<div class="headshot" style="background-image:url(resources/images/headshots/{headshot});"></div>', 
       '{firstName} {lastName}', 
       '<span>{title}</span>' 
      ].join(''), 

      items: [ 
       { 
        xtype: 'searchfield', 
        placeHolder: 'Buscar contacto...', 
        listeners: { 
         scope: this, 
         clearicontap: this.onSearchClearIconTap, 
         keyup: this.onSearchKeyUp 
        } 
       }, 
      ] 
     }, 
    ] 
}, 

/** 
* Llamado cuando la barra de busqueda tiene un evento keyup 
*/ 
onSearchKeyUp: function(field) { 
    //Se obtiene el store y el valor del field 
    var value = field.getValue(), 
     //store = this.getStore(); 
      //NOW: 
      store = Ext.data.StoreManager.lookup('Contactos'); 

    //se limpian los filtros actuales del store para comenzar la nueva busqueda 
    store.clearFilter(); 

    //Verificamos que el valor tenga alguna modificacion 
    if (value) { 
     //El usuario pudo haber introducido espacion en blanco,asi que los cortamos para poder recorrer todo el valor 
     var searches = value.split(' '), 
      regexps = [], 
      i; 

     //recorremos todo el valor 
     for (i = 0; i < searches.length; i++) { 
      //si no hay nada continuamos 
      if (!searches[i]) continue; 

      //Si encontramos algo creamos una expresion regular que es sensible a mayusculas 
      regexps.push(new RegExp(searches[i], 'i')); 
     } 

     //Ahora se filtra el store 
     //El metodo se pasara a cada record en el store 
     store.filter(function(record) { 
      var matched = []; 

      //Iteramos a traves de cada expresion regular 
      for (i = 0; i < regexps.length; i++) { 
       var search = regexps[i], 
        didMatch = record.get('firstName').match(search) || record.get('lastName').match(search); 

       //Si coincide el primer o ultimo nombre se coloca en la lista de los que coinciden 
       matched.push(didMatch); 
      } 

      //Si nada se consigue no se retorna nada 
      if (regexps.length > 1 && matched.indexOf(false) != -1) { 
       return false; 
      } else { 
       //Si no se muestra lo que se encontro 
       return matched[0]; 
      } 
     }); 
    } 
}, 
/** 
* Llamado cuando el usuario presiona el icono de 'x' en la barra de busqueda 
* Solo que quitan los filtros del store 
*/ 
onSearchClearIconTap: function() { 
    //this.getStore().clearFilter(); 
     //NOW: 
     store = Ext.data.StoreManager.lookup('Contactos'); 
} 
/** 
* Metodo llamado para tomar el store 
*/ 
     //I DELETE THIS FUNCTION 
/*getStore: function() { 
     this.store = 'myMoney.store.Contactos'*/ 
} 
}); 
+0

只是一個建議:你應該使用MVC結構,並有你的觀點和控制器,如果噸我不同的文件。它會更清晰。 – 2012-07-17 22:31:03

+0

我使用控制器,但在這裏我想要這個代碼工作,他們我試圖說清楚:/(我現在noobie):( – 2012-07-19 02:35:15

回答

0

請小心干將:)

getStore: function() { 
     this.store = 'myMoney.store.Contactos' 
} 

我認爲它打算返回店裏,不僅要分配給類成員。

onSearchKeyUp: function(field) { 
    //Se obtiene el store y el valor del field 
    var value = field.getValue(), 
     store = this.getStore(); // undefined 

變量永遠是不確定的...

+0

我覺得我有點笨,但是,你的解決方案是什麼?/ – 2012-07-19 02:29:51

+0

請參閱我的代碼的更新^^,你能嗎??:D – 2012-07-19 02:36:27

0

您需要使用Ext.StoreManager,爲了通過ID使用指定的商店。

例如:

與這家商店:

Ext.create('Ext.data.Store', { 
    model: 'SomeModel', 
    storeId: 'myStore' 
}); 

使用

var store = Ext.data.StoreManager.lookup('myStore'); 

或在視圖中使用它:

Ext.create('Ext.view.View', { 
    store: 'myStore', 
    // other configuration here 
}); 
+0

好吧,現在我沒有問題與「存儲沒有定義」,但代碼不工作..如果你能看到..我有一個商店已經定義('Contactos ')和我的列表可以加載信息。但搜索字段不工作..:/我有這個錯誤:未捕獲TypeError:無法讀取未定義的屬性'fn' – 2012-07-19 02:16:17

+0

請查看我的代碼的更新^^(// NOW:他們我寫更改)我不知道我是否想做別的 – 2012-07-19 02:36:15

+0

Uncaught TypeError:無法讀取未定義的屬性'fn' - 如果我評論「偵聽器:」塊代碼,此錯誤消失 – 2012-07-19 02:45:10

0

以上NeoMorfeo代碼是正確的唯一的事情在獲得商店val ue

您需要使用Ext.StoreManager,才能通過id使用指定的存儲。

例如:

與這家商店:

Ext.create('Ext.data.Store', { 
    model: 'SomeModel', 
    storeId: 'myStore' 
}); 

使用

var store = Ext.getStore('myStore'); 

或在視圖中使用它:

Ext.create('Ext.view.View', { 
    store: 'myStore', 
    // other configuration here 
}); 
相關問題