目前仅支持URL的CRUD。不需要的话可以却掉相关代码,把treegrid的data直接赋值给viewModel,然后用ko提交整个data
1、支持双击编辑
2、单击Cell,自动保存编辑。
3、4个功能按钮。
插件源码:
ko.bindingHandlers.etreegrid = {
editing: false,
editIndex: 0,
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var self = ko.bindingHandlers.etreegrid;
var opts = valueAccessor();
$(element).treegrid({
url: opts.url,
treeField: opts.treeField,
idField: opts.idField,
onDblClickRow: function (node) {
if (viewModel.add)
editRow(node);
},
onClickCell: function () {
if (viewModel.add) {
saveRow();
}
}
});
viewModel.add = function () {
addRow(getSelectedRow());
};
viewModel.edit = function () {
editRow(getSelectedRow());
};
viewModel.remove = function () {
removeRow(getSelectedRow());
};
viewModel.cancel = function () {
var node = getSelectedRow();
if (viewModel.onCancel) {
viewModel.onCancel(node);
}
$(element).treegrid("unselectAll");
try {
if (self.editing) {