开发者

Sencha Touch dynamically render a model

I have a database structure that is based on EAV model. Each objects has different kind of metafields with different names.

H开发者_JAVA百科ow could I create a Model in Sencha Touch that will be dynamic?

Thanks.

Regards,

Shafqat


There's nothing preventing you from creating the Models at run time.

function processEAV(attributes, types){

   var modelDef = {
      fields:[]
   }

   for(var i = 0, len = attributes.length; i < len; i++){
      modelDef.fields.push({name:attributes[i], type: types[i]});
   }

   Ext.regModel('NewModel', modelDef);

}

You can add all the additional properties that are needed like validations and associations.

This obviously isn't that great as you'll be doing it every time it is loaded. It may be better to, on the server, output the model definitions whenever they change and just include them into your mobile html document.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜