Reputation: 1309
I am working on webapi actually I need to split a string here I am getting data from controlers from data I had separated data like Menus and subMenus.
Like I am getting data
MenuName: "Home" "product" "setting" "orders" "contact " "Profile"
SubMenus for Product:
"viewProduct,Addproduct,searchProduct";
Here I need to split the submenus but the menus are not splitted. I don't know what's wrong.
Here is my code:
var Url = "/api/MenuItem";
(function($) {
$.buildMenu = function(MenuId, CurrentPage) {
$.getJSON(Url, function(data) {
alert(data);
var item = data;
$.each(data, function(k, v) {
var MenuItems = [];
MenuItems = v.MenuName;
alert(MenuItems);
var subitems = [];
subitems = v.SubMenUs;
alert(subitems);
var spltting = [];
var splitteditems = [];
spltting = subitems[0];
splitteditems = spltting.split(',');
alert(spltting.count());
alert(spltting.toString());
var count = new Array();
for (var n = 0; n < splitteditems.length; n++) {
count.push(parseInt(splitteditems[n]));
}
});
alert(item.toString());
$('.' + MenuId).append("<ul>");
for (var i = 0; i < item.length; i++) {
if (CurrentPage == item[i].MenuName)
$('.' + MenuId).append("<li><a class='main_menu_active'>" +
item[i].MenuName + "</a></li>"
);
else
$('.' + MenuId).append("<li> " +
item[i].MenuName + "</li>"
);
}
});
}
})(jQuery);
I need to split the subMenus and need to append to nested list.
Upvotes: 0
Views: 124
Reputation: 1570
jQuery is JavaScript, so this can be accomplished using the JavaScript String.split(",")
method.
Upvotes: 3