내 로컬 서버에서 JSON 데이터 파일을 읽으려면 Dojo와 Data/ItemFileWriteStore 모듈을 사용하고 있습니다. 내의 .js 그래서 ... 나는Dojo ItemFileWriteStore가 JSON 서버 파일을 읽지 않습니다.
var myDataStore = new ItemFileWriteStore({
url: "app/data/mydata.json",
handleAs: "json",
clearOnClose: true,
urlPreventCache: true
})
이 나의 복귀 선언 함수의 postCreate 함수에 위치를 파일 :
define([
"dojo/_base/declare",
"com/cayuse/base/_widget",
"dojo/text!./templates/myform.html",
...
"dojo/data/ItemFileWriteStore",
"dojo/store/DataStore",
"dojo/store/Observable",
"dojo/data/ObjectStore",
"dojo/domReady!"
],
function(declare, widget, template, ..., ItemFileWriteStore, DataStore,
Observable, ObjectStore){
return declare("app.myform", widget, {
templateString: template,
postCreate: function(){
domConstruct.create("link",{
type: "text/css",
rel: "stylesheet",
href: require.toUrl('dojox/form/resources/CheckedMultiSelect.css')
}, document.getElementsByTagName("head")[0]);
// data store
var myDataStore = new ItemFileWriteStore({
url: "app/data/mydata.json",
handleAs: "json",
clearOnClose: true,
urlPreventCache: true
})
console.log(myDataStore);
}
});
}
);
나는 위에서 보는 것과 데이터 저장소 액세스를 변경할 수 있습니다 IFWS 방법을 사용하여
var myDataStore = dojo.xhrGet({
url: "app/data/mydata.json",
handleAs: "json",
load: function(data, ioArgs){
console.log(data);
}
});
으로 설정하고 아무 문제없이 파일을 찾습니다.
이것은 너무 기괴합니다! 여기서 무엇이 잘못 될지에 대한 아이디어가 있습니까?
업데이트 : 여기는 내가 읽은 파일의 데이터입니다. 나는 그것이 JSON 형식을 따르는 것으로 믿는다. 그렇지 않으면 알려주세요. xhr 잘 읽습니다.
{ "identifier": "id",
"label": "firstName",
"items":[
{"id":"0","firstName":"Robert","website":"www.barker.com","email":"[email protected]","bday":"1928-08-09","color":"Blue","toolkits":["Dojo","Moo"],"sendEmail":["on"],"format":"HTML"},
{"id":"1","firstName":"Vanna","website":"www.white.com","email":"[email protected]","bday":"1968-07-23","color":"Green","toolkits":["Dojo","jQuery"],"sendEmail":["off"],"format":"Text"}
]
}
응답 eburgos에 감사드립니다. 파일 데이터를 게시 했어야합니다. 그것은 그 구조를 준수합니다. 나는 그것을 나의 지위에 추가 할 것이다. 한 가지 사실은이 포럼 상태에서 속성과 값 모두 진정한 JSON 형식으로 인용해야한다는 것입니다. 두 가지 방법을 시도했지만 문제는 파일을 가져 오지 못한다는 것입니다. 나는 Net XHR 활동에서 Firebug를보고 파일에 손대지 않는다. 게다가 dojo xhr을 사용할 때 같은 파일을 잘 읽습니다. 정말 이상 하네, 내가 가진이 문제 야. – teaman
그래서 Firebug Net XHR 활동이 요청을하지 않습니까? – eburgos