Add dynamic input and append json serialize treeview

4 posts, 0 answers
  1. Alfredo
    Alfredo avatar
    3 posts
    Member since:
    Nov 2013

    Posted 20 Jan 2014 Link to this post

    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);
  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2596 posts

    Posted 22 Jan 2014 Link to this post

    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!
  3. Alfredo
    Alfredo avatar
    3 posts
    Member since:
    Nov 2013

    Posted 23 Jan 2014 Link to this post

    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...

  4. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2596 posts

    Posted 27 Jan 2014 Link to this post

    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!
Back to Top