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:

stores : ['UserStore']

The store

Ext.define('MyApp.store.UserStore', {
extend : 'Ext.data.Store',
xtype : 'userstore',
config : {
model : 'MyApp.model.User',
autoLoad : true,
proxy : {
type : 'ajax',
url : 'php/get_user.php',
reader : {
type : 'json',
rootProperty : 'users'
}
},
listeners : {
beforeload : function() {
console.log('Before load');
},
load : function(store) {
console.log('load');
}
}
}
});

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

Ext.define('MyApp.view.Profile', {
extend : 'Ext.Panel',
xtype : 'profileview', requires : ['MyApp.store.UserStore', 'Ext.List', 'Ext.DataView', 'Ext.data.Store'], config : {
layout : 'fit',
title : 'Profiel',
iconCls : 'user3',
cls : 'home',
scrollable : true,
styleHtmlContent : true,
html : ['<h1>Mijn Profiel</h1>'].join(""),
items : [Ext.create('Ext.DataView', {
store : 'userstore',
itemTpl : '<h2>{USERNAME}</h2><p>{EMAIL}</p>'
})]
}
});

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).

Ext.define('MyApp.view.Profile', {
extend: 'Ext.Panel',
xtype: 'profileview', requires: ['MyApp.store.UserStore', 'Ext.List', 'Ext.DataView', 'Ext.data.Store'], config: {
layout: 'fit',
title: 'Profiel',
iconCls: 'user3',
cls: 'home',
scrollable: true,
styleHtmlContent: true,
html: ['<h1>Mijn Profiel</h1>'].join("")
}, initialize: function () {
var me = this; //Create the instance of the store and load it
var userStore = Ext.create('MyApp.store.UserStore');
userStore.load(); //Create the dataview
var view = Ext.create('Ext.DataView', {
store: userStore,
itemTpl: '<h2>{USERNAME}</h2><p>{EMAIL}</p>'
});
//Add the dataview to the panel
me.add(view);
}
});




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


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. 第5模块闯关Bootstrap

    “行(row)”必须包含在 .container (固定宽度)或 .container-fluid (100% 宽度)中,以便为其赋予合适的排列(aligment)和内补(padding). 通过“行 ...

  2. PIC24 通过USB在线升级 -- USB CDC bootloader

    了解bootloader的实现,请加QQ: 1273623966 (验证填bootloader):欢迎咨询或定制bootloader:我的博客主页www.cnblogs.com/geekygeek 今 ...

  3. elasticsearch-mathc和term的区分

    elasticsearch和mysql在思想上是有不同的,elasticsearch有分词一说,比如北京奥运分词成北京,奥运,北京奥运.分词要要考虑两点,一个是查询字符串要不要分词,还有就是原存储字段 ...

  4. 「暑期训练」「基础DP」 Monkey and Banana (HDU-1069)

    题意与分析 给定立方体(个数不限),求最多能堆叠(堆叠要求上方的方块严格小于下方方块)的高度. 表面上个数不限,问题是堆叠的要求决定了每个方块最多可以使用三次.然后就是对3n" role=& ...

  5. Python面试315题

    感谢老男孩的武沛齐老师辛苦整理和分享,本文是转自他的博客. 第一部分 Python基础篇(80题) 为什么学习Python? 通过什么途径学习的Python? Python和Java.PHP.C.C# ...

  6. 第十五篇 Python之文件处理

    一 文件操作  介绍 计算机系统分为:计算机硬件,操作系统,应用程序三部分. 我们用python或其他语言编写的应用程序若想要把数据永久保存下来,必须要保存于硬盘中,这就涉及到应用程序要操作硬件,众所 ...

  7. FlaskWeb开发从入门到放弃(二)

    第5章 章节五 01 内容概要 02 内容回顾 03 面向对象相关补充:metaclass(一) 04 面向对象相关补充:metaclass(二) 05 WTforms实例化流程分析(一) 06 WT ...

  8. tensorflow的几种优化器

    最近自己用CNN跑了下MINIST,准确率很低(迭代过程中),跑了几个epoch,我就直接stop了,感觉哪有问题,随即排查了下,同时查阅了网上其他人的blog,并没有发现什么问题 之后copy了一篇 ...

  9. day-12 python实现简单线性回归和多元线性回归算法

    1.问题引入  在统计学中,线性回归是利用称为线性回归方程的最小二乘函数对一个或多个自变量和因变量之间关系进行建模的一种回归分析.这种函数是一个或多个称为回归系数的模型参数的线性组合.一个带有一个自变 ...

  10. 关于c++的头文件依赖

    正在看google c++编程规范,里面对头文件依赖是这么说的: 使用前置声明(forward declarations)尽量减少.h文件中#include的数量. 当一个头文件被包含的同时也引入了一 ...