source 源對(duì)象表示一組鍵/值對(duì)募舟。
The source object represents a set of key/value pairs.
url: A string containing the URL to which the request is sent.
data: Data to be sent to the server.
localdata: data array or data string pointing to a local data source.
datatype: the data's type. Possible values: 'xml', 'json', 'jsonp', 'tsv', 'csv', 'local', 'array', 'observablearray'.
type: The type of request to make ("POST" or "GET"), default is "GET".
id: A string containing the Id data field.
root: A string describing where the data begins and all other loops begin from this element.
record: A string describing the information for a particular record.
datafields: An array describing the fields in a particular record. Each datafield must define the following members:
name - A string containing the data field's name.
type(optional) - A string containing the data field's type. Possible values: 'string', 'date', 'number', 'bool'.
format(optional) - Sets the data formatting. By setting the format, the jqxDataAdapter plug-in will try to format the data before loading it.
Example: { name: 'SubmitDate', type: 'date', format: "yyyy-MM-ddTHH:mm:ss-HH:mm" }
map(optional) - A mapping to the data field.
url:請(qǐng)求地址恨旱,即數(shù)據(jù)來(lái)源,例如當(dāng)datatype類(lèi)型為xml壳坪,即需要url請(qǐng)求到目標(biāo)文件獲取數(shù)據(jù)
var source = {
datatype:"xml",
url="../sampledata/products.xml"
}
data:發(fā)送到服務(wù)器的數(shù)據(jù)柳刮,目前還沒(méi)有遇到,補(bǔ)充中...
localdata:本地?cái)?shù)據(jù)祷蝌,與url功能相同;
datatype:數(shù)據(jù)類(lèi)型帆卓,如果用url獲取數(shù)據(jù)巨朦,則需要確保datatype正確,用localdata則無(wú)要求剑令,類(lèi)型有 'xml', 'json', 'jsonp', 'tsv', 'csv', 'local', 'array', 'observablearray';
type:請(qǐng)求類(lèi)型糊啡,post、get吁津,默認(rèn)為get棚蓄;
id:用處不詳?碍脏?梭依?
root:即一條數(shù)據(jù)被什么元素包裹,
root:"demo"
xml文件
<demo>
<content type="application/xml">
<m:properties>
<d:ShipVia m:type="Edm.Int32">3</d:ShipVia>
<d:Freight m:type="Edm.Decimal">32.3800</d:Freight>
</m:properties>
</content>
</demo>
record:與root用法相同典尾。
datafields:表格通過(guò)什么字段取值役拴,其中name字段為必須,即localdata或者url中數(shù)據(jù)的字段名钾埂,type河闰,可有可無(wú),可能的值:'string'褥紫,'date'姜性,'number','bool'髓考;format部念,可有可無(wú),管道或者過(guò)濾器绳军,僅支持時(shí)間印机;map,可有可無(wú)门驾,xml的映射路徑射赛;
Example with XML data:
{ name: 'CompanyName', map: 'm\\:properties>d\\:CompanyName' }
XML
<content type="application/xml">
<m:properties>
<d:CustomerID>ALFKI</d:CustomerID>
<d:CompanyName>Alfreds Futterkiste</d:CompanyName>
</m:properties>
</content>
*** ***
Example with nested JSON data.
var data = [{ "empName": "test", "age": "67", "department": { "id": "1234", "name": "Sales" }, "author": "ravi"}];
// prepare the data
var source =
{
datatype: "json",
datafields: [
{ name: 'empName' },
{ name: 'age' },
{ name: 'id', map: 'department>id' },
{ name: 'name', map: 'department>name' },
{ name: 'author' }
],
localdata: data
};
var dataAdapter = new $.jqx.dataAdapter(source);
注意事項(xiàng)
當(dāng)使用source 對(duì)象時(shí),需要引入jqxdata.js
requires jqxdata.js
但是奶是,當(dāng)我們用source生成源數(shù)據(jù)后楣责,還不能直接被jqxGrid使用竣灌,需要通過(guò)jqx的內(nèi)置方法轉(zhuǎn)換之后才能使用
var dataAdapter = new $.jqx.dataAdapter(source);