2016-02-14 58 views
0

我不知道如何判断,但我仍然没有把它做对。这是我的代码:以'0'为前缀的存储号码

Ext.define("PL.view.list.listOnly", { 
    extend: 'Ext.form.Panel', 
    alias: 'widget.listlistonly', 
    config:{ 
     fullscreen: true, 
     title: 'Master barang', 
     items:[{ 
      xtype : 'panel', 
      layout: { 
       type: 'fit', 
       align : 'stretch', 
       pack : 'start', 
      }, 
      defaults: { 
       allowBlank: true, 
       msgTarget: 'side', 
       labelWidth: 60, 
       margin: '5 5 5 5', 
      }, 
      items:[{ 
        xtype:'list', 
        height: '100%', 
        masked: { xtype: 'loadmask',message: 'Loading...' }, 
        scrollable: { 
         direction: 'vertical', 
         directionLock: true 
        }, 
        store:{ 
         fields: [{ 
           name:'szName', 
          },{ 
           name:'szProductID', 
          },{ 
           name:'szBarcode', 
         }], 
         autoLoad: true, 
         pageSize: 20, 
         proxy: { 
          type: 'ajax', 
          url: 'store/product/loadData.php', 
          pageParam: 'param', 
          reader: { 
           type: 'json', 
           rootProperty: 'topics', 
          } 
         } 
        }, 
        variableHeights: false, 
        useComponents: true, 
        itemTpl: '<div class="myButton">' + 
        '<input type="button" name="{szProductID}" value="Edit" ' + 
        'style="padding:3px;">' + 
        '</div>' + 
        '<div class="myContent">'+ 
        '<div>PLU : <b>{szProductID}</b>, Barcode: <b>{szBarcode}</b></b></div>' + 
        '<div>Nama: <b>{szName}</b></div>' + 
        '</div>', 
       }] 
      }],   
     scrollable : false, 
    }, 
}); 

这是我从JSON获得:

{"topics": [{ 
     "szProductID": 1001, 
     "szBarcode": 002, 
     "szName": "STANDARD BLACK" 
    },{ 
     "szProductID": 1100420020479, 
     "szBarcode": 1100420020479, 
     "szName": "STANDARD BLUE" 
     }], 
"totalCount": 2} 

正如你可以看到,有一个“002”(szBarcode场),这是我的问题。该列表仅显示'2'而不是'002'。这应该显示'002'为szBarcode,但我不知道如何解决这个问题。

任何帮助将不胜感激

+0

你控制JSON吗? – trincot

+0

嗨trincot ...你是什么意思控制JSON? – Viandry

回答

0

的问题是,barcode: 002barcode: 2意味着JSON格式完全相同。数字的前缀零不计数。

大概有四种不同的东西可以做。

  1. 如果您可以访问服务器代码,则可以更改它以将条形码字段作为字符串发送给您(barcode:"002")。
  2. 如果您的条形码总是有一定的长度(如13),您可以使用您的号码,并再次将其填充到所需的长度。请注意,经过一定的长度后,存在精度问题,因为数字存储在固定长度的内存中,而字符串的内存总是随需要而变长。采样转换代码:
    name:'barcode', convert:function(value) { var str = value.toString(), pad = "0000000000000"; // expand to length of your number return pad.substring(0, pad.length - str.length) + str); }
    (奖金:此代码不打破,当有人不(1)之后...)
  3. 如果你在你的JSON没有其他条码领域,你可以使用正则表达式来添加在反序列化之前向JSON客户端提供必要的引号。
  4. 您可以覆盖ExtJS的默认JSON序列化/反序列化代码。请注意,这不像听起来那么容易,并且可能具有相当多的副作用。如果您想要将条形码作为零填充的JSON号码发送回服务器,则这是唯一合适的方法。
+0

嗨亚历山大......我已经完成了第1步到第3步,作为我的临时解决方案。对于第4步,我需要为此而思考......无论如何,谢谢Alex – Viandry

+0

这不是四个步骤,而是四种不同的解决方案 - 你只需要做其中的一个...... – Alexander