I have a UserStore that I want to load after succesful login of a user. I can't get this to work i.e. find a pattern to do this.

I now have the UserStore in the app.js like this:

  1. stores : ['UserStore']

The store

  1. Ext.define('MyApp.store.UserStore', {
  2. extend : 'Ext.data.Store',
  3. xtype : 'userstore',
  4. config : {
  5. model : 'MyApp.model.User',
  6. autoLoad : true,
  7. proxy : {
  8. type : 'ajax',
  9. url : 'php/get_user.php',
  10. reader : {
  11. type : 'json',
  12. rootProperty : 'users'
  13. }
  14. },
  15. listeners : {
  16. beforeload : function() {
  17. console.log('Before load');
  18. },
  19. load : function(store) {
  20. console.log('load');
  21. }
  22. }
  23. }
  24. });

The user is retrieved based on the php $_SESSION['userid'] which is not set before a user is loggedin.

When starting up the app the store is loaded but it doesn't find any data. I need to go back to the beginning to log in again and then of course the session id was set in the previous login.

What I am trying to accomplish is either to lazy load the store or to autoload only when needed by the View.

I have tried this but I can't get it to work.

This is what I did:

option 1

I removed the UserStore from app.js and added a require and xtype item to the View but then I get [WARN][Ext.dataview.DataView#applyStore] The specified Store cannot be found

The View

  1. Ext.define('MyApp.view.Profile', {
  2. extend : 'Ext.Panel',
  3. xtype : 'profileview',
  4. requires : ['MyApp.store.UserStore', 'Ext.List', 'Ext.DataView', 'Ext.data.Store'],
  5. config : {
  6. layout : 'fit',
  7. title : 'Profiel',
  8. iconCls : 'user3',
  9. cls : 'home',
  10. scrollable : true,
  11. styleHtmlContent : true,
  12. html : ['<h1>Mijn Profiel</h1>'].join(""),
  13. items : [Ext.create('Ext.DataView', {
  14. store : 'userstore',
  15. itemTpl : '<h2>{USERNAME}</h2><p>{EMAIL}</p>'
  16. })]
  17. }
  18. });

Option 2

try to find out if I can set the autoload to false and load in on demand via some listener. But I can't find out exactly how.

So, how can this be achieved and what is the best pattern to do this.

Thanks for your help! Ext.dataview.DataView#applyStore The specified Store cannot be found

 

1 Answer

up vote3 down vote accepted

I actually never assign stores this way: store : 'userstore'. A better way is to create an instance of the store and load it yourself, using the autoLoad: false on my stores, I don't like them loading at start of the app. Try this (I can't test it because I'm not usually programming touch apps).

  1. Ext.define('MyApp.view.Profile', {
  2. extend: 'Ext.Panel',
  3. xtype: 'profileview',
  4. requires: ['MyApp.store.UserStore', 'Ext.List', 'Ext.DataView', 'Ext.data.Store'],
  5. config: {
  6. layout: 'fit',
  7. title: 'Profiel',
  8. iconCls: 'user3',
  9. cls: 'home',
  10. scrollable: true,
  11. styleHtmlContent: true,
  12. html: ['<h1>Mijn Profiel</h1>'].join("")
  13. },
  14. initialize: function () {
  15. var me = this;
  16. //Create the instance of the store and load it
  17. var userStore = Ext.create('MyApp.store.UserStore');
  18. userStore.load();
  19. //Create the dataview
  20. var view = Ext.create('Ext.DataView', {
  21. store: userStore,
  22. itemTpl: '<h2>{USERNAME}</h2><p>{EMAIL}</p>'
  23. });
  24. //Add the dataview to the panel
  25. me.add(view);
  26. }
  27. });




关注公众号,分享干货,讨论技术


Sencha Touch MVC 中 store 的使用的更多相关文章

  1. Sencha Touch 2.2 Store Proxy 异常监控

    移动端到服务端通信往往会发生很多莫名的异常情况,如何有效的监控proxy异常,给用户友好的用户体验呢? Proxy给我提供了异常exception的监听事件,只需要监控该项目即可. Sencha To ...

  2. sencha touch dataview 中添加 button 等复杂布局并添加监听事件

    config 中的属性默认都会自动生成   getter   setter  applier  updater 四个方法. applier 在调用  setter 时被调用, updater 在属性值 ...

  3. Sencha Touch 2中如何动态添加button

    原理很简单无非就是在一个容器上面选中id,用容器的add方法将button循环加入. 现在我们来试一下 1.先定义一个Container组件用,以后在里面添加button ? 1 2 xtype:'c ...

  4. sencha touch mvc

    controller: Ext.define('MyApp2.controller.MyController1', { extend: 'Ext.app.Controller', config: { ...

  5. sencha touch 2中判断游览器是否包含webkit的方法

    <script type="text/javascript"> if (!Ext.browser.is.WebKit) { alert("The curren ...

  6. 【翻译】Sencha Touch 2入门:创建一个实用的天气应用程序之三

    原文:Getting Started with Sencha Touch 2: Build a Weather Utility App (Part 3) 作者:Lee BoonstraLee is a ...

  7. sencha touch 常见问题解答(26-50)

    26.sencha touch在华为.红米等部分手机下hide事件失效,msgbox无法关闭怎么办 答:请看http://www.cnblogs.com/cjpx00008/p/3535557.htm ...

  8. 第四步 使用 adt-eclipse 打包 Cordova (3.0及其以上版本) + sencha touch 项目

    cordova最新中文api http://cordova.apache.org/docs/zh/3.1.0/ 1.将Cordova 生成的项目导入到adt-eclipse中,如下: 项目结构如下: ...

  9. Sencha Touch 2 实现跨域访问

    最近要做手机移动App,最后采用HTMML5来做框架用Sencha Touch,在数据交互时遇到了Ajax跨域访问,在Sencha Touch 2中,实现跨域访问可以使用Ext类库提供给我们的类Ext ...

随机推荐

  1. Hadoop:WordCount分析

    相关代码: package com.hadoop; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.P ...

  2. Vue-router用法

    #全局守卫- router.beforeEach(to,from,next){} #全局后置钩子- router.afterEach(to,from){} #路由独享守卫- beforeEnter(t ...

  3. Delphi实例之绘制正弦函数图像

    Delphi实例之绘制正弦函数图像 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphic ...

  4. nginx启动和配置

    1.命令行参数 -c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的.路径应为绝对路径 -t 不运行,而仅仅测试配置文件.nginx 将检查配置文件的语 ...

  5. Python 并发编程:PoolExecutor 篇

    个人笔记,如有疏漏,还请指正. 使用多线程(threading)和多进程(multiprocessing)完成常规的并发需求,在启动的时候 start.join 等步骤不能省,复杂的需要还要用 1-2 ...

  6. UVA 11882 Biggest Number(搜索+剪枝)

    You have a maze with obstacles and non-zero digits in it: You can start from any square, walk in the ...

  7. cygwin上编译RPC框架thrift

    cygwin的配置就不多说了,缺什么就通过安装器安装好了. 在thrift的官网下载 thrift-0.11.0源码,通过cmake编译,生成Makefile之后,make出现编译错误 /cygdri ...

  8. c语言实现带LRU机制的哈希表

    #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h&g ...

  9. lintcode-104-合并k个排序链表

    104-合并k个排序链表 合并k个排序链表,并且返回合并后的排序链表.尝试分析和描述其复杂度. 样例 给出3个排序链表[2->4->null,null,-1->null],返回 -1 ...

  10. 条件查询Criteria

    public User getUserByNameCri(String name){ Session session = null; User user = null; try { session = ...