不適合なJSONデータ用のカスタムアダプターを実装しています。
// map function has not been overridden - RESTAdapter is super.
DS.ArcGisAdapter.map("App.Cai", {
caiId: { key: "CAIID" },
name: { key: "ANCHORNAME" }
});
そして、私の主キーの場合:
App.restSerializer.configure("App.Cai", {
primaryKey: "CAIID"
});
このApp.Cai
ような(モデル)で:
var attr = DS.attr,
belongsTo = DS.belongsTo;
App.Cai = DS.Model.extend({
caiId: attr("string"),
name: attr("string")
});
私のテンプレートから、{{debugger}}
&を介してこのデータ (プレゼンテーション用に短縮) を取得してい{{log item}}
ます。
_data: {
attributes: {
caiId: null
name: null
},
id: null
},
id:"130012000149"
ご覧のとおり、ID はトップ レベルで取得されていますが、その下にはマッピングされてcaiId
おらず、name
そこにもありません。以下は、findQuery
私のカスタム アダプターの関数です。
findQuery: function(store, type, query, recordArray) {
var root = this.rootForType(type),
transformedJSON = {},
adapter = this,
rejectionHandler = function (reason) {
Ember.Logger.error(reason, reason.message);
throw reason;
};
return this.ajax(this.buildURL(root), "GET", {
data: query
}).then(function(json){
var feature,
index = 0;
root = root + "s";
transformedJSON[root] = [];
for(;index < json.features.length; index++) {
feature = json.features[index];
transformedJSON[root].push(feature.attributes);
}
adapter.didFindQuery(store, type, transformedJSON, recordArray);
}).then(null, rejectionHandler);
}
どんなアイデアでも大歓迎です!ありがとう :) PS 他に情報が必要な場合はお知らせください。
編集:変換前/変換後の JSON データへのGist 。
編集 2:ハックを思いつきましたが、これで問題は解決しません。
JSONSerializer を拡張し、アダプターのシリアライザーとして設定しました。keyForAttributeName
マッピングが何も返さない場合のフォールバックであるフックを実装する必要がありました。これが私の実装です:
keyForAttributeName: function (type, name) {
var attributes = (Ember.meta(DS.ArcGisAdapter, true)["DS.Mappable"] || {}).attributes,
guid = Ember.guidFor(type.toString()),
result = name;
if (attributes && guid) {
result = attributes.values[guid][name].key;
}
return result;
}
モデルのマップが欠落している理由について、引き続きヘルプを探しています。