extjs中model

Ext.define('Dock',{
extend : 'Ext.data.Model',
fields : [{name:'dockId',type:'string',mapping:'dockId'},
   {name:'dockNo',type:'string',mapping:'dockNo'},
  {name:'dockSiteName',type:'string',mapping:'bikeSite.siteName'},
   {name:'dockStatus',type:'string',mapping:'dockStatus'},
   {name:'bikeInfos',mapping:'bikes'},
   {name:'dockRentCount',type:'int',mapping:'dockRentCount'},
         {name:'dockReturnCount',type:'int',mapping:'dockReturnCount'},      {name:'dockProductionTime',type:'string',mapping:'dockProductionTime'},           {name:'dockStartUseTime',type:'string',mapping:'dockStartUseTime'}]
});


var docks_store=Ext.create("Ext.data.Store",{
model:"Dock",
autoLoad:true,
pageSize: 10,
proxy:{
type:"ajax",
url:"dock/lists",
reader : {
type : 'json',
root : 'docklist',
totalProperty : 'total'
}
}
});


var  query_params;
docks_store.on('beforeload',function(store){
  Ext.apply(store.proxy.extraParams,query_params);
})


var grid=Ext.create("Ext.grid.Panel",{
renderTo : 'grid',
width : "100%",
frame: true,
forceFit: true,
emptyText:"暂无锁柱",
store : docks_store,
selModel:Ext.create('Ext.selection.CheckboxModel'),
columns : [ {
dataIndex : 'dockSiteName',
text:'网点名称'
},{
text : '锁柱编号',
dataIndex : 'dockNo'
},{
text : '状态',
dataIndex :'dockStatus',
renderer: function(value){
if(value==1){
return "<img src='images/extjs/ok.png' title='正常'/>";
}else{
return "<img src='images/extjs/bad.png' title='损坏'/>";
}
}
}, {
text : '自行车数量',
dataIndex : 'bikeInfos',
renderer: function(value){
if(value.length>0){
return "1";
}else{
return "0";
}
}Ext.Msg.confirm("确认信息", "确认删除该锁柱吗?", function(button, text) { 
       if (button == "yes"){
       var selections=grid.getSelectionModel().getSelection();
for( var i = 0 ; i < selections.length ; i++ ){
var is_bike=selections[i].get("bikeInfos").length;
if(is_bike<1){
var dockId= selections[i].get("dockId");
        Ext.Ajax.request({

extjs中当无法确定web后台传来的值是何种数据类型(set,list对象)时,不要写type:,
mapping:对象(bikes)就行了,var is_bike=selections[i].get("bikeInfos").length;直接能获取到这个集合的长度,

猜你喜欢

转载自jianhao-wang.iteye.com/blog/2040292