Exj JS 5,来自ViewController的Access Store / Model

时间:2015-05-08 05:24:49

标签: javascript extjs extjs-mvc extjs5

我想从ViewController加载项目/项目。这是一个例子:

Ext.define('MyApp.model.User', {
   extend: 'Ext.data.Model',
   fields: ['name', 'email'],
   proxy: {
       type: 'rest',
       ...
   }
});

Ext.define('MyApp.store.User', {
   extend: 'Ext.data.Store',
   model: 'MyApp.model.User',
   data : [
    {firstName: 'Seth',    age: '34'},
    {firstName: 'Scott', age: '72'},
    {firstName: 'Gary', age: '19'},
    {firstName: 'Capybara', age: '208'}
   ]
});

Ext.define('MyApp.view.MainController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.main',

    init: function() {
        //how to access store here and load items, using its load() method?
        //how to access model here and load an item, using its load() method?
    }
});
  1. 如何从此处访问商店并使用其load()方法加载项目?
  2. 如何使用其加载方法访问模型并加载项目?

1 个答案:

答案 0 :(得分:5)

> npm WARN engine yo@1.4.6: wanted: {"node":">=0.10.0","npm":">=2.1.0"}
> (current: {"node":"v0.10.29","npm":"1.4.14"}) |
> 
> 
> > buffertools@2.1.2 install C:\Users\blabla\AppData\Roaming\npm\node_m odules\generator-mobileangularui\node_modules\slug\node_modules\unicode\node_mod
> ules\bufferstream\node_modules\buffertools
> > node-gyp rebuild
> 
> /
> C:\Users\blabla\AppData\Roaming\npm\node_modules\generator-mobileangul
> arui\node_modules\slug\node_modules\unicode\node_modules\bufferstream\node_modul
> es\buffertools>node "C:\Program
> Files\nodejs\node_modules\npm\bin\node-gyp-bin\\
> ..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild gyp ERR!
> configure error gyp ERR! stack Error: Can't find Python executable
> "python", you can set the PYT HON env variable. gyp ERR! stack     at
> failNoPython (C:\Program Files\nodejs\node_modules\npm\nod
> e_modules\node-gyp\lib\configure.js:103:14) gyp ERR! stack     at
> C:\Program Files\nodejs\node_modules\npm\node_modules\node
> -gyp\lib\configure.js:64:11 gyp ERR! stack     at Object.oncomplete (fs.js:107:15) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command
> "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modu
> les\\node-gyp\\bin\\node-gyp.js" "rebuild" gyp ERR! cwd
> C:\Users\blabla\AppData\Roaming\npm\node_modules\generato
> r-mobileangularui\node_modules\slug\node_modules\unicode\node_modules\bufferstre
> am\node_modules\buffertools gyp ERR! node -v v0.10.29 gyp ERR!
> node-gyp -v v0.13.1 gyp ERR! not ok npm WARN optional dep failed,
> continuing buffertools@2.1.2
> 
> 
> > unicode@0.6.1 postinstall C:\Users\blabla\AppData\Roaming\npm\node_m odules\generator-mobileangularui\node_modules\slug\node_modules\unicode
> > node install.js
> 
> try to read file /usr/share/unicode/UnicodeData.txt . Warning: using
> slow naiv Buffer.indexOf function! `npm install buffertools` to speed
> things up. /usr/share/unicode/UnicodeData.txt not found. try to read
> file /usr/share/unicode-data/UnicodeData.txt .
> /usr/share/unicode-data/UnicodeData.txt not found. try to read file
> UnicodeData.txt . UnicodeData.txt not found. try to download . GET
> unicode.org:80/Public/UNIDATA/UnicodeData.txt
> C:\Users\blabla\AppData\Roaming\npm\gulp -> C:\Users\blabla\
> AppData\Roaming\npm\node_modules\gulp\bin\gulp.js
> C:\Users\blabla\AppData\Roaming\npm\yo -> C:\Users\blabla\Ap
> pData\Roaming\npm\node_modules\yo\lib\cli.js Error while downloading
> UnicodeData.txt: Error: connect ECONNREFUSED Please download file
> manually, put it next to the install.js file and run `node install.js`
> again. /
> 
> 
> > yo@1.4.6 postinstall C:\Users\blabla\AppData\Roaming\npm\node_module s\yo
> > yodoctor
> 
> | Yeoman Doctor Running sanity checks on your system
> 
> V Global configuration file is valid V NODE_PATH matches the npm root
> V No .bowerrc file in home directory V No .yo-rc.json file in home
> directory
> 
> Everything looks all right! npm ERR! unicode@0.6.1 postinstall: `node
> install.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the
> unicode@0.6.1 postinstall script. npm ERR! This is most likely a
> problem with the unicode package, npm ERR! not with npm itself. npm
> ERR! Tell the author that this fails on your system: npm ERR!     node
> install.js npm ERR! You can get their info via: npm ERR!     npm owner
> ls unicode npm ERR! There is likely additional logging output above.
> 
> npm ERR! System Windows_NT 6.1.7601 npm ERR! command "C:\\Program
> Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
> ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "bower" "yo"
> "gulp" "gen erator-mobileangularui" npm ERR! cwd C:\Users\blabla npm
> ERR! node -v v0.10.29 npm ERR! npm -v 1.4.14 npm ERR! code ELIFECYCLE
> C:\Users\blabla\AppData\Roaming\npm\bower -> C:\Users\blabla
> \AppData\Roaming\npm\node_modules\bower\bin\bower npm ERR! npm ERR!
> Additional logging details can be found in: npm ERR!    
> C:\Users\blabla\npm-debug.log npm ERR! not ok code 0

你甚至可以这样做,

this.getView().getStore() // get the store from the controller's view
this.getStore('name') // get store by name
this.getViewModel.getStore('store key') // get store from the View model using the key of the store
  

“视图控制器是一个可以附加到特定控制器的控制器   查看实例,以便它可以管理视图及其子组件。   视图的每个实例都有一个新的视图控制器,所以   实例是孤立的。“

ViewController必须与View关联。没有观点,它没有重要意义。 ViewController用于处理与其视图相关的所有控件:路由,事件处理程序......如果您使用的是MVVM设计,您还应该为视图使用ViewModel(虽然不是强制性的)。如果您正确设置了MVVM,那么您可以使用ViewController和ViewModel已经提供的默认方法轻松获取关联商店和模型的实例。

  

getStore(姓名): Ext.data.Store获取附加到的Ext.data.Store   ViewModel附加到此控制器。请参阅Ext.app.ViewModel.getStore。

请检查MVVM architecture。 我还发现Saki的示例非常有用:http://extjs.eu/ext-examples/#complex-data-binding-5