extjs的视图模型和绑定

深度绑定
 
myinfo: {
    autoLoad:true,
    model:'EPMMS.model.Memberinfo',
    proxy: {
        type:'ajax',
        url : 'start/index',
        extraParams:{my:true},
        reader: {
            type: 'json',
            rootProperty: 'memberinfo'
        }
    },
}

formulas:{
    info:{
        bind:{bindTo:'{myinfo}',deep:true},//显式绑定+深度绑定
        get:function(store){
            return store.first();
        }
    }
}
 
 
 
使用deep:tree选项,当bindTo选项指定的内容发生任何改变时都触发get计算,否者只有当对象引用改变时才触发get计算,如果myinfo的值是动态获取的就必须用这种方式才能读取到值。
显示绑定
get方法通过回调函数和bindTo传递参数,而不是Extjs检测可能引用的对象引用,要使用deep绑定,必须用显示绑定
 
model绑定
links:{ theUser:{ type:'User', id:17}},
 
id为model的id,extjs会自动发起请求,model需要配置proxy选项
把model的属性直接释放到viewModel中,可以直接访问属性名,也可以访问theUser对象
 
记录绑定
Ext.create('Ext.Component',{ bind:{ data:{ reference:'User', id:42}}});
 
关联记录绑定
Similar to a record bind, one can also bind to an association, say the User's Address record:
Ext.create('Ext.Component',{ bind:{ data:{ reference:'User', id:42, association:'address'}}});

猜你喜欢

转载自haohetao.iteye.com/blog/2395795