在ajax获取后更新一个可淘汰的淘汰属性 [英] Updating one observable property of knockout after ajax get

查看:74
本文介绍了在ajax获取后更新一个可淘汰的淘汰属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试使用AJAX get在我的淘汰应用程序中实现过滤,我想只更新viewmodel中众多可观察对象中的一个。

这是我在JS中的viewmodel



Hi,

I am trying to implement a filtering in my knockout application using a AJAX get and i want to update only one of the many observables in the viewmodel.
This is my viewmodel here in JS

function containerViewModel() {
    mainViewModel = this;
    mainViewModel.isBusy = ko.observable(false);
    mainViewModel.errorMessage = ko.observable("");
    mainViewModel.containerModel = ko.observable(
        {
            HomeSettings: ko.observable(),
            Employee: ko.observable({ HeaderText: '', BodyText: '', FooterText: '' }),
            Class: ko.observable({ HeaderText: '', BodyText: '', FooterText: '' }),
            Degree: ko.observable({ HeaderText: '', BodyText: '', FooterText: '' }),
            Specialization: ko.observable({ HeaderText: '', BodyText: '', FooterText: '' }),
            IDEAData: ko.observable({ HeaderText: '', BodyText: '', FooterText: '' })
        }
        );

    GET_AllContainer(mainViewModel);
}





这些可观察对象中的每一个都显示在不同的标签中,每个标签都有过滤按钮。当我从任何选项卡单击过滤器按钮时,我使用ajax调用获取数据。但问题是我获取整个数据并绑定到viewmodel这个





Each of these observables are shown in different tabs and each tab has filter buttons. When i click the filter button from any tab, i fetch the data using ajax call. But the problem is am getting the whole data and binding to the viewmodel as this

function GET_FilteredContainer(mainView, filterText, productID, FilterID) {
    mainViewModel.isBusy(true);
    $.ajax({
        url: hostApi + api_GetAllContainer,
        contentType: "json",
        data: { FilterLinkIds: filterText, ProductID: productID },
        success: function (result) {
            mainView.containerModel(result);            
            SetFilterButtonCSS(productID, FilterID);
            ProductReportsNotFound(result);
            mainViewModel.isBusy(false);
        },
        error: function (result) {
            mainViewModel.errorMessage(result);
            mainViewModel.isBusy(false);
        }
    });

}





但这意味着它将清除其他标签的过滤器。那么有什么方法我只能更新所需的observable



谢谢



But this means it will clear the filter of other tabs. So is there any way i can update only the required observable only

Thanks

推荐答案

.ajax( {
url:hostApi + api_GetAllContainer,
contentType: json
data:{FilterLinkIds:filterText,ProductID:productID},
success: function (result){
mainView.containerModel(result) ;
SetFilterButtonCSS(productID,FilterID);
ProductReportsNotFound(result);
mainViewModel.isBusy( false );
},
错误: function (结果){
mainViewModel.errorMessage(result);
mainViewModel.isBusy( false );
}
});

}
.ajax({ url: hostApi + api_GetAllContainer, contentType: "json", data: { FilterLinkIds: filterText, ProductID: productID }, success: function (result) { mainView.containerModel(result); SetFilterButtonCSS(productID, FilterID); ProductReportsNotFound(result); mainViewModel.isBusy(false); }, error: function (result) { mainViewModel.errorMessage(result); mainViewModel.isBusy(false); } }); }





但这意味着它将清除其他标签的过滤器。那么有什么方法我只能更新所需的observable



谢谢



But this means it will clear the filter of other tabs. So is there any way i can update only the required observable only

Thanks


这篇关于在ajax获取后更新一个可淘汰的淘汰属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆