要注意MODEL的定义和实例化的代码,注释掉的是老式的不兼容4.0以上的。而下面的定义才是新推荐的。

我网上可是查的了。是书上的代码老了。

<!DOCTYPE html>
<html>
<head>
    <title>ExtJs</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" type="text/css" href="ExtJs/packages/ext-theme-crisp/build/resources/ext-theme-crisp-all.css">
		<script type="text/javascript" src="ExtJs/ext-all.js"></script>
		<script type="text/javascript" src="ExtJs/bootstrap.js"></script>
		<script type="text/javascript" src="ExtJs/packages/ext-theme-crisp/build/ext-theme-crisp.js"></script>

    <script type="text/javascript">
			Ext.onReady(function(){
        Ext.QuickTips.init();
        var inputForm = Ext.create('Ext.form.Panel', {
          bodyPadding: 5,
          width: 600,
          flex: 1,
          fieldDefaults: {
            labelSeparator: ': ',
            labelWidth: 80,
            width: 180,
            msgTarget: 'side',
            allowBlank: false,
            labelAlign: 'right'
          },
          layout: {
            type: 'hbox',
            align: 'middle'
          },
          defaultType: 'textfield',
          items: [{
            fieldLabel: '产品名称',
            name: 'productName'
          },{
            fieldLabel: '数量',
            xtype: 'numberfield',
            name: 'productNum'
          },{
            fieldLabel: '金额',
            xtype: 'numberfield',
            name: 'productPrice'
          }],
          fbar: [{
            text: '增加',
            handler: function(){
              if(inputForm.getForm().isValid()){
                var data = inputForm.getForm().getValues();
                //var product = Ext.ModelMgr.create(data, 'ProductInfo');
                var product = Ext.create('ProductInfo', data);
                productStore.add(product);
                inputForm.getForm().reset();
              }
            }
          }]
        });

        //Ext.regModel('ProductInfo', {
        //  fields: ['productName', 'productNum', 'productPrice']
        //});

        Ext.define('ProductInfo', {
            extend: 'Ext.data.Model',
            fields: [
              {name: 'productName'},
              {name: 'productNum'},
              {name: 'productPrice'}
            ]
        });

        var productStore = Ext.create('Ext.data.Store', {
          autoLoad: true,
          data: [],
          model: 'ProductInfo',
          proxy: {
            type: 'memory',
            reader: {
              type: 'json',
              rootProperty: 'datas'
            }
          }
        });

        var productTpl = new Ext.XTemplate(
          '<table border=1 cellspacing=1 cellpadding=1 width=100%>',
          '<tr><td width=160>产品名称</td><td width=75>数量</td><td width=75>金额</td></tr>',
          '<tpl for=".">',
          '<tr><td>{productName}</td><td>{productNum}</td><td>{productPrice}</td></tr>',
          '</tpl>',
          '</table>'
        );
        var productView = Ext.create('Ext.view.View', {
          store: productStore,
          tpl: productTpl,
          deferEmptyText: false,
          itemSelector: 'div.thumb-wrap',
          emptyText: '请录入商品'
        });

        var productViewPanel = Ext.create('Ext.panel.Panel', {
          autoScroll: true,
          width: 600,
          flex: 3,
          layout: 'fit',
          bodyStyle: 'background-color: #FE5623',
          items: productView
        });
        Ext.create('Ext.panel.Panel', {
          renderTo: document.body,
          frame: true,
          width: 800,
          height:500,
          layout: 'vbox',
          title: '产品录入',
          items: [inputForm, productViewPanel]
        });
      });
    </script>
</head>
<body>
<div id='tpl-table1'></div>
<br>
<div id='tpl-table2'></div>
</body>
</html>

  

ExtJs之Ext.view.View的更多相关文章

  1. [转载]ExtJs4 笔记(11) Ext.ListView、Ext.view.View 数据视图

    本篇介绍两个用来展示数据的容器控件,分别是Ext.ListView和Ext.view.View.Ext.ListView就是大名鼎鼎的 Ext GridPanel的前身,不过现在的Ext4已经将它整合 ...

  2. ExtJs4 笔记(11) Ext.ListView、Ext.view.View 数据视图

    本篇介绍两个用来展示数据的容器控件,分别是Ext.ListView和Ext.view.View.Ext.ListView就是大名鼎鼎的Ext GridPanel的前身,不过现在的Ext4已经将它整合到 ...

  3. ExtJS学习-----------Ext.Array,ExtJS对javascript中的Array的扩展

    关于ExtJS对javascript中的Array的扩展.能够參考其帮助文档,文档下载地址:http://download.csdn.net/detail/z1137730824/7748893 因为 ...

  4. ExtJS学习-----------Ext.Object,ExtJS对javascript中的Object的扩展

    关于ExtJS对javascript中的Object的扩展.能够參考其帮助文档,文档下载地址:http://download.csdn.net/detail/z1137730824/7748893 以 ...

  5. Android 拖动View View跟随手指一动

    /** * 拖动View 配合onTouchListener使用 * 设置View的布局属性,使得view随着手指移动 注意:view所在的布局必须使用RelativeLayout 而且不得设置居中等 ...

  6. public void onItemClick(AdapterView arg0, View view, int position,long arg3)详解【整理自网络】

    参考自: http://blog.csdn.net/zwq1457/article/details/8282717 http://blog.iamzsx.me/show.html?id=147001 ...

  7. ListView onItemClick(AdapterView<?> parent, View view, int position, long id)参数详解

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) { parent.getA ...

  8. Android API之android.view.View.MeasureSpec

    android.view.View.MeasureSpec MeasureSpec是View的内部类 public static class MeasureSpec MeasureSpec封装从par ...

  9. onItemClick(AdapterView<?> parent, View view, int position, long id)

    Public Methods public abstract void onItemClick (AdapterView<?> parent, View view, int positio ...

随机推荐

  1. Elasticsearch源码分析—线程池(十一) ——就是从队列里处理请求

    Elasticsearch源码分析—线程池(十一) 转自:https://www.felayman.com/articles/2017/11/10/1510291570687.html 线程池 每个节 ...

  2. [HDU4689]Derangement

    https://zybuluo.com/ysner/note/1232641 题面 给出\(b_1,b_2,...,b_n\in\{−1,1\}\),求满足\((p_i−i)*b_i<0\)的\ ...

  3. How to add dependency on a Windows Service AFTER the service is installed

    his can also be done via an elevated command prompt using the sc command. The syntax is: sc config [ ...

  4. 捣鼓TinyMCE粘贴图片并上传+Flask后台

    好久没有编程了,最近需要完成一个小功能,为了方便,需要粘贴图片后上传到后台.前台编辑器用tinymce(N年前用过,我也就知道这个编辑器而已.这次使用下来感觉文档更丰富了),后台我用的Flask.昨天 ...

  5. Appium + python -always_allows弹窗

    from appium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.web ...

  6. 通过JS制作一个简易数码时钟

    设计思路: 数码时钟即通过图片数字来显示当前时间,需要显示的图片的URL根据时间变化而变化. a.获取当前时间Date()并将当前时间信息转换为一个6位的字符串; b.根据时间字符串每个位置对应的数字 ...

  7. C - Arrival of the General

    Problem description A Ministry for Defense sent a general to inspect the Super Secret Military Squad ...

  8. # Nginx常见问题

    try_files的使用 按顺序检查文件是否 存在 location /{ try_files $uri $uri/ /index.php } 解析:在/下寻找$uri,如果没有找到,则去找$uri/ ...

  9. JavaScript中字符串运算符的使用

    字符串运算符是用于两个字符串型数据之间的运算符,它的作用是将两个字符串连接起来.在JavaScript中,可以使用+和+=运算符对两个字符串进行连接运算.其中,+运算符用于连接两个字符串,而+=运算符 ...

  10. Eclipse的菜单简介

    在Eclipse工作台的上方提供了菜单栏,该菜单栏包含了实现Eclipse各项功能的命令,并且与编辑器相关,即菜单栏中的菜单项与当前编辑器内打开的文件是关联的.例如,编辑器内没有打开任何文件,那么,将 ...