使用Knockout在客户端检查数据并基于该绑定表

人气:381 发布:2022-09-22 标签: knockout.js Knockout.js

问题描述

我正在使用MVC& amp;为该公司开发一个Web应用程序。昏死。我对MVC和Knockout非常陌生。在管理员方面,我需要以网格格式显示已申请,批准,拒绝的用户。 我写控制器以获取AllUsers并且我能够绑定表格中的所有用户。我想使用knockout在客户端过滤它们以减少到DB的往返。它将提高我的应用程序性能。 所以,我需要的是:如何使用Knockout检查用户是否已批准或拒绝,并根据我需要的检查将这些数据绑定到单独的表格。 我搜索了这个,我无法正确理解,因为我对这项技术非常陌生。 有些人可以帮我这个。 这里是我的客户端代码使用Knock out

Hi, I am developing a web application for the firm using MVC & Knockout. I am very much new to MVC and Knockout. In the admin side I need to display the users who are applied, approved, rejected in the Grid format. I wrote controller to get AllUsers and I can able to bind all those users to Table. And I want to filter them at the client side using knockout to reduce the round trips to DB. It will boost my application performance. So, what I need is: how can I check whether the user is Approved or Rejected using Knockout and based on that check I need to bind that data to separate Tables. I googled about this and I could not able to understand properly as I am very much new to this Technology. Can some body help me on this. here is my client side code using Knock out

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 ApprovedUsers = {
        UserName: self.UserName,
        ContactNo: self.ContactNo,
        Email: self.Email,
        User_ID: self.User_ID,
        IsApproved: self.IsApproved     
    };

    self.ApprovedUsers = ko.observableArray();

    $.ajax({
          url: "Home/GetAllUsers",
          cache: false,
          type: "JSON",
          contentType: "application/json; charset=utf-8",
          data: {},
          success: function(data){
               self.ApprovedUsers(data);  
          }
    });
}

$(document).ready(function(){
     var viewModel = new UserViewModel();
     ko.applyBindings(viewModel);
});

我可以使用上面的代码绑定所有数据,但它是包括所有类型的用户(已批准,已应用和已拒绝)。 如何在客户端检查PropertyIsApproved的值并根据我如何使用KnockOut过滤数据? 提前致谢 Murali Krishna

I can able to bind all the data by using the above code, but it was included all type users (Approved, Applied & Rejected). How can I check the value of Property "IsApproved" on client side and based on that How can I filter the data using KnockOut? Thanks in advance Murali Krishna

推荐答案

.ajax({ url:< span class =code-string> Home / GetAllUsers, cache: false ,类型: JSON, contentType:< span class =code-string> application / json; charset = utf-8, data:{},成功:功能(数据){ self.ApprovedUsers(data); } }); } .ajax({ url: "Home/GetAllUsers", cache: false, type: "JSON", contentType: "application/json; charset=utf-8", data: {}, success: function(data){ self.ApprovedUsers(data); } }); }

( document )。ready( function (){ var viewModel = new UserViewModel(); ko。 applyBindings(viewModel); }); (document).ready(function(){ var viewModel = new UserViewModel(); ko.applyBindings(viewModel); });

我可以使用上面的代码绑定所有数据,但是它包括所有类型的用户(已批准,已应用和已拒绝)。 如何在客户端检查PropertyIsApproved的值并根据我如何使用KnockOut过滤数据? 提前致谢 Murali Krishna

I can able to bind all the data by using the above code, but it was included all type users (Approved, Applied & Rejected). How can I check the value of Property "IsApproved" on client side and based on that How can I filter the data using KnockOut? Thanks in advance Murali Krishna

535