TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Murali krishna Ande
NA
57
51.8k
Convert computed output to observableArray using Knockout
Dec 18 2013 2:00 AM
Hi,
I am getting all the Applied Users at once and binding them in a Table1. And I am filtering the users based on the approval and binding them to Table2 by using the below code.
function UserViewModel(){
var self=this;
self.UserName = ko.observable("");
self.ContactNo = ko.observable("");
self.Email = ko.observable("");
self.User_ID = ko.observable("");
self.IsApproved = ko.observable("");
var Users = {
UserName: self.UserName,
ContactNo: self.ContactNo,
Email: self.Email,
User_ID: self.User_ID,
IsApproved: self.IsApproved
};
self.Users = ko.observableArray();
$.ajax({
url: "Home/GetAllUsers",
cache: false,
type: "JSON",
contentType: "application/json; charset=utf-8",
data: {},
success: function(data){
self.ApprovedUsers(data);
}
});
self.ApprovedUsers = ko.observableArray();
self.ApprovedUsers = ko.computed(function(){
return ko.utils.arrayFilter(self.User(),function(item){
return item.IsApproved === 1
});
});
}
$(document).ready(function(){
var viewModel = new UserViewModel();
ko.applyBindings(viewModel);
});
My Requirement is:
When admin approved the user from Table1 I want to remove that user from Table1 and add him to Table2.
My Problem Is:
I am getting the filtered data in observable format, but for that one I cannot able to write the methods either "PUSH" or "REMOVE".
1. How can I get the ObservableArray from the ko.computed.? or
2. Filter the ObservableArray data and return the data in observableArray format. How can I do that.?
Can some body plz help me on this.
Thanks in Advance,
Murali Krishna.
Reply
Answers (
4
)
webhosting and domain name register
how to highlight a menu link when clicked