2
我正在嘗試使用查詢引擎 SQLike,並且正在努力應對基本概念。SQLike - 瞭解基礎知識
我用我的數據源的JSON來自於我的PHP代碼,像這樣:
var placesJSON=<? echo json_encode($arrPlaces) ?>;
下面是一個示例JSON:
var placesJSON=[{"id":"100","name":"Martinique","type":"CTRY"},{"id":"101","name":"Mauritania","type":"CTRY"},{"id":"102","name":"Mauritius","type":"CTRY"},{"id":"103","name":"Mexico","type":"CTRY"},{"id":"799","name":"Northern Mexico","type":"SUBCTRY"},{"id":"800","name":"Southern Mexico","type":"SUBCTRY"},{"id":"951","name":"Central Mexico","type":"SUBCTRY"},{"id":"104","name":"Micronesia, Federated States","type":"CTRY"},{"id":"105","name":"Moldova","type":"CTRY"}];
我理解(通過這個reference),其我首先需要像這樣解壓我的JSON:
var placesData = SQLike.q(
{
Unpack: placesJSON,
Columns: ['id','name','type']
}
)
然後下一步是查詢結果就像這樣:
var selectedPlaces = SQLike.q(
{
Select: ['*'],
From: placesData,
OrderBy: ['name','|desc|']
}
最後,以顯示我應該使用類似瀏覽器的結果:
document.getElementById("myDiv").innerHTML=selectedPlaces[0].name
這是行不通的。我得到的錯誤是:selectedPlaces [0] .name是未定義的。
我很確定我錯過了很簡單的事情。任何提示?
請發佈什麼'placesJSON'包含 – georg
thg435,我編輯的問題包括一個示例JSON。從我所能看到的 – einav
中,沒有必要「解開」這個Json,因爲它已經是一個對象數組。 – georg