gpt4 book ai didi

jquery - 如何在 json 属性中执行函数?

转载 作者:行者123 更新时间:2023-12-01 06:59:26 27 4
gpt4 key购买 nike

我从服务器返回这个 json:

{
"Id": 0,
"Name": ko.observable('New Product'),
"PurchasePrice": 0.0,
"DownPayment": 0.0,
"TotalPayment": 0.0,
"MortgageInsurance": 0.0,
"PurchaseOrRefinance": null,
"Client": null,
"MonthlyCosts": null,
"ClosingCosts": null,
"FirstLien": null,
"SecondLien": null
}

我使用 jQuery.getJson 检索它,如下所示:

function addProduct(){
$.getJSON('@Url.Action("GetNewProduct","Product")',function(data){
viewModel.products.push(data);
});
viewModel.productSaved(false);
viewModel.product(products[products.length - 1]);

}

但是,代码似乎从未运行过。仅当我在 json 中返回该函数时才会发生这种情况,如果删除该函数,一切都会正常运行。有没有办法解决这个问题?

最佳答案

应该是这样的>

返回此

{"Id":0,"Name":'New Product',"PurchasePrice":0.0,"DownPayment":0.0,"TotalPayment":0.0,"MortgageInsurance":0.0,"PurchaseOrRefinance":null,"Client":null,"MonthlyCosts":null,"ClosingCosts":null,"FirstLien":null,"SecondLien":null}

像这样>

    function addProduct(){
$.getJSON('@Url.Action("GetNewProduct","Product")',function(data){
data.Name = ko.observable(data.Name);
viewModel.products.push(data);
});
viewModel.productSaved(false);
viewModel.product(products[products.length - 1]);

}

关于jquery - 如何在 json 属性中执行函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5254982/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com