Здравствуйте, коллеги.
Нужна консультация, по поводу динамически загружаемых контейнеров.
Кейс такой:
Есть отрендеренный контейнер через Ext.create("Terrasoft.Container", _viewConfig) . Как в отрендеренный контейнер добавить еще контейнеры?
Нравится
Код вот такой.
[code]
createBody: function() {
createBody: function() {
var _model = {
values: {},
columns: {},
methods: {
init: function() {
this.set("_id", Terrasoft.generateGUID());
this.set("_items", []);
this.set("_rows", new Terrasoft.Collection());
this.setRendered(false);
},
setConfig: function(config) {
this.set("_config", config || []);
},
getConfig: function() {
return (this.get("_config"));
},
setRendered: function(f) {
this.set("_isRendered", f);
},
isRendered: function() {
return (this.get("_isRendered"));
},
getId: function() {
return (this.get("_id"));
},
/**
* @returns {Terrasoft.Collection}
*/
getRowConfig: function() {
var _items = new Terrasoft.Collection(),
_config = this.getConfig();
_config.forEach(function(confItem) {
var _item = {
name: confItem.name,
dataValueType: confItem.dataValueType,
caption: (Terrasoft.isUndefined(confItem.caption) ? "[N/D]" : confItem.caption),
isRequired: (Terrasoft.isUndefined(confItem.isRequired) ? false : confItem.isRequired),
visible: (Terrasoft.isUndefined(confItem.visible) ? true : confItem.visible)
};
if (confItem.hasOwnProperty("isLookup")) {
_item.isLookup = confItem.isLookup;
}
if (confItem.hasOwnProperty("referenceSchema")) {
_item.referenceSchema = confItem.referenceSchema;
}
if (confItem.hasOwnProperty("defaultValue")) {
_item.defaultValue = confItem.defaultValue;
}
_items.add(confItem.name, _item);
});
return (_items);
},
/**
*
* @returns {Terrasoft.Collection}
*/
getRows: function() {
return (this.get("_rows"));
},
getRowsViews: function() {
var _items = [];
this.getRows().each(function(row) {
if (!row.isRendered()) {
row.render();
}
_items.push(row.getView());
});
return (_items);
},
getView: function() {
return (this.get("_container"));
},
getViewConfig2: function() {
var _config = this.getViewConfig();
_config.items = this.getRowsViews();
return(_config);
},
getViewConfig: function() {
var _id = "TableBody_" + this.getId();
return ({
id: _id,
selectors: { wrapEl: "#" + _id },
classes: {wrapClassName: ["im-table-body"]},
items: this.get("_items")
});
},
render: function() {
var _container = null;
if (!this.isRendered()) {
this.set("_items", this.getRowsViews());
var _viewConfig = this.getViewConfig();
_container = Ext.create("Terrasoft.Container", _viewConfig);
this.setRendered(true);
}
this.set("_container", _container);
},
reRender: function() {
if (this.isRendered()) {
this.set("_items", this.getRowsViews());
this.getView().reRender();
}
},
createRow: function() {
var _config = this.getRowConfig().getItems();
var _model = {
values: {},
columns: {},
methods: {
init: function(id) {
id = id || Terrasoft.generateGUID();
this.set("_id", id);
this.set("_items", []);
this.setConfig(_config);
this.setEditMode(false);
this.setRendered(false);
},
getId: function() {
return (this.get("_id"));
},
setConfig: function(config) {
this.set("_config", config);
},
getConfig: function() {
return (this.get("_config"));
},
setEditMode: function(f) {
this.set("_isEditMode", f);
},
isEditMode: function() {
return (this.get("_isEditMode"));
},
setRendered: function(f) {
this.set("_isRendered", f);
},
isRendered: function() {
return (this.get("_isRendered"));
},
getData: function() {
},
getView: function() {
return (this.get("_container"));
},
getViewConfig: function() {
var _id = "TableRow_" + this.getId();
return ({
id: _id,
selectors: { wrapEl: "#" + _id },
classes: {wrapClassName: ["im-table-header"]},
items: this.get("_items")
});
},
getColumnModel: function(config) {
var itemDataValueType = config.dataValueType;
var itemName = config.name;
var itemId = "Row" + this.getId() + "_" + itemName;
var controlConfig = {};
switch (itemDataValueType) {
case Terrasoft.DataValueType.TEXT:
controlConfig = {
id: itemId + "Label",
className: "Terrasoft.Label",
caption: {bidTo: itemName},
isRequired: config.isRequired
};
break;
}
return controlConfig;
},
getRowConfig: function() {
var _config = this.getConfig(),
_items = new Terrasoft.Collection();
_config.forEach(function(confItem) {
_items.add(this.getColumnModel(confItem));
}, this);
return (_items);
},
render: function() {
var _container = null;
if (!this.isRendered()) {
this.set("_items", this.getRowConfig().getItems());
var _viewConfig = this.getViewConfig();
_container = Ext.create("Terrasoft.Container", _viewConfig);
this.setRendered(true);
}
this.set("_container", _container);
},
reRender: function() {
if (this.isRendered()) {
this.set("_items", this.getRowConfig().getItems());
this.getView().reRender();
}
}
}
};
_config.forEach(function(confItem) {
var _name = confItem.name,
_column = {
dataValueType: confItem.dataValueType,
caption: confItem.caption,
isRequired: confItem.isRequired,
type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN
},
_value = confItem.defaultValue || null;
if (confItem.dataValueType === Terrasoft.DataValueType.LOOKUP) {
_column.isLookup = confItem.isLookup || false;
_column.referenceSchemaName = confItem.referenceSchemaName;
_model.values[_name + "List"] = new Terrasoft.Collection();
}
_model.values[_name] = _value;
_model.columns[_name] = _column;
});
var _rowViewModel = Ext.create("Terrasoft.BaseViewModel", _model);
_rowViewModel.Ext = Ext;
_rowViewModel.sandbox = sandbox;
_rowViewModel.Terrasoft = Terrasoft;
return _rowViewModel;
},
addRow: function(collection) {
if (collection.getCount() > 0) {
var _id = Terrasoft.generateGUID(),
_row = this.createRow();
_row.init(_id);
_row.set("Id", _id);
collection.eachKey(function(key, val) {
_row.set(key, val);
});
this.getRows().add(_row);
this.reRender();
}
}
}
};
var _bodyViewModel = Ext.create("Terrasoft.BaseViewModel", _model);
_bodyViewModel.Ext = Ext;
_bodyViewModel.sandbox = sandbox;
_bodyViewModel.Terrasoft = Terrasoft;
return _bodyViewModel;
}
[/code]
Извините, Илья, что так долго.
1. версия 7.7
2. "разрулил" вопрос через JQuery