0

I'm using Teleriks Kendo-UI with MVC to build a MVVM model for a treeview like this ...

var viewModel = kendo.observable({
                isVisible: true,
                items: kendo.observableHierarchy(@Html.Raw(Json.Encode(Model.items))),
               ....

All is good, but then I have some signalR clients on the page that accept "events" for the model so I added ...

            addItem: function(parentId, item){
                // how do query the hierarchy?
            },
            deleteItem: function(itemId) {
                // again how do i query the hierarchy?
            },

... to the above model in order to accept these event notifications when called from my signalR code.

The problem I have is that I have a hierarchy but no idea how to get the data item in this context where the item has the given id then add the given item to its children.

I am assuming this is the right approach though right?

My theory being that "x happened on server", that results in "notify client" which calls "add item" passing a parentid and the item to be added to the tree. By adding to the model the item should then "just appear in the tree".

But how do I query the item collection and its children recursively on the client because I don't have linq in this context?

War
  • 8,539
  • 4
  • 46
  • 98

1 Answers1

0

I think you would just have to write a recursive function to iterate over the hierarchy and check the objects for the one you want.

This question is similar: Underscore.js findWhere nested objects

If you like using Linq in .NET, you may want to look at Underscore.js or LowDash for similar functionality in JavaScript.

Community
  • 1
  • 1
CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138
  • I think you're probably right, i have pulled jslinq through nuget i'm just experimenting with recursive functions now. Frustrating having such a powerful server sdie framework then hitting this sort of problem on the client! – War Jul 02 '14 at 14:09