![](/img/trans.png)
[英]The option to add an ADO.net data entity to my SL business application is not there. How can I find it?
[英]How can I [simply] consume JSON Data in a Line of Business Web Application
我通常使用JSON和jQuery來返回帶有html的字符串。 但是,我想在我的代碼中開始使用Javascript對象。
在我的頁面上開始使用json對象的最簡單方法是什么?
這是一個示例Ajax調用(當然在$(document).ready( { ... })
:
$('#btn').click(function(event) {
event.preventDefault();
var out = $('#result');
$.ajax({ url: "CustomerServices.asmx/GetCustomersByInvoiceCount",
success: function(msg) {
//
// Iterate through the json results and spit them out to a page?
//
},
data: "{ 'invoiceCount' : 100 }"
});
});
我的WebMethod:
[WebMethod(Description="Gets customers with more than n invoices")]
public List<Customer> GetCustomersByInvoiceCount(int? invoiceCount) {
using (dbDataContext db = new dbDataContext()) {
return db.Customers.Where(c => c.InvoiceCount >= invoiceCount);
}
}
返回的內容:
{"d":[{"__type":"Customer","Account":"1116317","Name":"SOME COMPANY","Address":"UNit 1 , 392 JOHN ST. ","LastTransaction":"\/Date(1268294400000)\/","HighestBalance":13922.34},{"__type":"Customer","Account":"1116318","Name":"ANOTHER COMPANY","Address":"UNIT #345 , 392 JOHN ST. ","LastTransaction":"\/Date(1265097600000)\/","HighestBalance":549.42}]}
我想知道的是,人們通常用這個返回的json做什么? 你是否迭代了屬性並動態創建一個html表?
有沒有辦法使用javascript版本的反射(類似.Net GridView控件)“綁定”JSON數據
您是否將此返回的數據放入Javascript對象中,然后對其執行某些操作?
我想要實現的一個例子是在銷售人員的客戶列表中有一個簡單的'html頁面(在移動設備上)。 當單擊其中一個客戶時,客戶ID將被發送到Web服務,該Web服務檢索與銷售人員相關的客戶詳細信息。
我知道SO人才庫非常深,所以我認為你們所有人都能夠指導正確的方向並給出一些關於最佳方法的想法。
我建議您查看各種客戶端模板解決方案。 有集成的甚至會談中下一個jQuery的版本在這里 。
我更喜歡jTemplate,因為它簡單,體積小。 但還有其他人。 如果您想查看它的實際情況,請在此處查看我們的客戶網站。 我們發現它甚至可以很好地擴展到大量行(> 1000)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.