each(Function f,[Object scope]):void 变量数据中的Model
实例: 1.(function(){ Ext.Loader.setConfig({ enabled:true //这三行代码是用来启用Loader的 }); Ext.onReady(function(){ Ext.define('person', { extend: 'Ext.data.Model', fields: [ {name: 'name', type: 'string'}, {name: 'age', type: 'int'}, ], proxy:{ type:'memory' } }) var s = Ext.create('Ext.data.Store', { model: 'person', data:[ {name:'uspcat.com',age:18}, {name:'wfc',age:23}, ], autoLoad: true }); s.each(function(model){ alert(model.get('name')); }) }) })();
程序如下: (function(){ Ext.Loader.setConfig({ enabled:true //这三行代码是用来启用Loader的 }); Ext.onReady(function(){ // Ext.define('person', { // extend: 'Ext.data.Model', // fields: [ // {name: 'name', type: 'string'}, // {name: 'age', type: 'int'}, // ], // proxy:{ // type:'memory' // } // }) var s = Ext.create('Ext.data.Store', { // model: 'person', fields: [ {name: 'name', type: 'string'}, {name: 'age', type: 'int'}, ], data:[ {name:'uspcat.com',age:18}, {name:'wfc',age:23}, ], autoLoad: true }); s.each(function(model){ alert(model.get('name')); }) }) })();小主意地方:
下面我们看看ajax请求:
(function(){ Ext.Loader.setConfig({ enabled:true //这三行代码是用来启用Loader的 }); Ext.onReady(function(){ var s = Ext.create('Ext.data.Store', { fields: [ {name: 'name'}, {name: 'age'}, ], proxy: { type: 'ajax', url: 'person.jsp', }, }); s.load(function(records, operation, success) { Ext.Array.each(records,function(model){ }); // s.filter('name',"wfc"); s.each(function(model){ // alert(model.get('name')); }); var index=s.find('name',"wfc",0,false,true,false); alert(index); }); }) })();
find的用法,这些用法都需要在API Doc上看看OK。
下面看看:person.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% //response.getWriter().write("[['wangfangchen',26]]"); //System.out.println(request.getParameter("id")); response.getWriter().write("[{name:'uspcat.com',age:26},{name:'wfc',age:26}]"); //response.getWriter().write("[{name:'uspcat.com',age:26,email:'[email protected]'}]"); //,{name:'wf',age:2} %>