This is a migrated thread and some comments may be shown as answers.

Add dynamic input and append json serialize treeview

3 Answers 107 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Alfredo
Top achievements
Rank 1
Alfredo asked on 20 Jan 2014, 09:13 PM
Hi,

I'm having trouble adding a dynamic node in treeview using append.
I added html controls concatenated input text, but when I do the serialization to json using "toJSON" and move to the C # gives error.

How do I use editable template or template and regatando value of input along with the serialization of my treeview?

tried using "template:", but always shows "undefined"...

how do use?????

Ex:
treeview.append(
  {
           IdNo: objItem.IdNo,
           NomeNo: '<input type=\"text\" pattern=\"^[\+\-]{0,1}([ 0-9]+\.){0,1}[ 0-9]+$\" title=\"' + objItem.NomeNo + '\" maxlength=\"30\" class=\"input-medium\" id=\"txtMontante' + objItem.IdNo + '\" name=\"txtMt' + objItem.IdNo + '\" />'
  }, treeNodeText);

3 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 22 Jan 2014, 01:06 PM
Hello Alfredo,

I am not really sure what exactly the issue is. I have created a simple example, showing how to append a node to a TreeView, I hope it will help:

http://jsbin.com/UxoNUHe/1/edit

Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alfredo
Top achievements
Rank 1
answered on 23 Jan 2014, 11:16 AM
hello,

I'm actually finding it difficult to recover the value of the input type text placed using "append". The template seems not work then concat with my description of the node text field and it worked, but the difficulty is in getting the value of input text instead of a not checkbox.

Example:
treeview.append({
                                      Id: item.Id,
                                      Text: item.Desc +  <input type=text />'
                                 }, oldTreeItem);

I do not know if it's right, but I was rescued the node where the input and updated the field by setting a new value for a sign that I took and then removed all the html content to generate the json.

See as it was:

var treeview = $("#treeView").data("kendoTreeView");
        $('#treeView').find('input').each(function () {
            var li = $(this).closest(".k-item")[0];
            var node = treeview.dataSource.getByUid(li.getAttribute('data-uid'));
            node.set("value", $(this).val());
        });

at the end of regular expression used to delete html tags to generate the json and go to my controller:  stringJson.replace(/<\/?[^>]+>/gi, '');

has something better that I could not see and do?

thks...

0
Kiril Nikolov
Telerik team
answered on 27 Jan 2014, 08:11 AM
Hello Alfredo,

I am still not really sure what exactly you are trying to achieve. However your code seems perfectly valid, and if you want to just set the text from the input to the node of the treeview it will do the job perfectly.

Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Alfredo
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Alfredo
Top achievements
Rank 1
Share this question
or