관련 모델 저장소에서 데이터를 검색하는 중 멈추었습니다. 달성하고자하는 것에 대한 간단한 개요를 알려주십시오.Sencha Touch 1.xx - 서버 프록시에서 관련 모델로드
퀴즈 목록이 필요하며 퀴즈를 탭하면 질문 목록이 표시됩니다. 질문을 탭하면 연관된 객관식 답을 얻을 수 있습니다 (어쩌면 버튼이나 다른 목록이있는 데이터보기 일 수도 있습니다).
이전 베타 테스트에서는 평면 트리 스토어를 사용하여 퀴즈를 표시했지만 미학에서는 제한적이었으며 내 데이터를 API와 매우 쉽게 동기화 할 수 없었기 때문에 관련 모델을 얻으려고합니다. 대신 일하고있어. 나는 비슷한 문제를 온라인에서 찾지 못했다.
다음은 관련 코드입니다 (MVC 설정에서).
QuizModel.js :
app.models.QuizModel = Ext.regModel("QuizModel", {
fields: [
{ name: 'id', type: 'int' },
{ name: 'studentid', type: 'int' },
{ name: 'dateAllocated', type: 'string' },
{ name: 'category', type: 'string' },
],
associations: [
{type: 'hasMany', model: 'QuestionModel', name: 'questions'},
],
proxy: {
type: 'rest',
actionMethods: {create: "POST", read: "POST", update: "PUT", destroy: "DELETE"},
url: 'http://localhost/bm/core/api/quiz',
reader: {
type: 'json',
root: 'quizes'
}
}
});
app.stores.QuizStore = new Ext.data.Store({
model: "QuizModel",
storeId: 'quizStore'
});
QuestionModel.js :
app.models.QuestionModel = Ext.regModel("QuestionModel", {
fields: [
{ name: 'id', type: 'int' },
{ name: 'quizmodel_id', type: 'int'},
{ name: 'prompt', type: 'string' },
{ name: 'level', type: 'int' },
{ name: 'categoty', type: 'string' }
],
associations: [
{type: 'hasMany', model: 'AnswerModel', name: 'answers'},
{type: 'belongsTo', model: 'QuizModel'}
]
});
AnswerModel.js :
app.models.AnswerModel = Ext.regModel("AnswerModel", {
fields: [
{ name: 'id', type: 'int' },
{ name: 'questionmodel_id', type: 'int' },
{ name: 'prompt', type: 'string' },
{ name: 'correct', type: 'string' }
],
associations: [
{type: 'belongsTo', model: 'QuestionModel'}
]
});
QuizController.js :
나는 3 개 관련 모델을 가지고app.controllers.QuizController = new Ext.Controller({
index: function(options) {
console.log('home');
},
quizTap: function(options){
var currentQuiz = app.stores.QuizStore.getAt(options.index);
var questions = currentQuiz.questions().load().getAt(0);
app.views.questionList.updateWithRecord(questions);
app.views.viewport.setActiveItem(
app.views.questionList, options.animation
);
}
});
,
그리고 마지막으로, 내 나머지 API 응답은 다음과 같이 보입니다 :
{
"status" : true,
"quizes" : [{
"id" : "1",
"category" : "Privacy",
"date_allocated" : "1329363878",
"questions" : [{
"id" : "1",
"prompt" : "Lorem ipsum dolor sit amet?",
"answers" : [{
"id" : "1",
"correct" : "1",
"prompt" : "yes"
},
{
"id" : "2",
"correct" : "0",
"prompt" : "no"
}]
}]
}]
}
이 결과 : 이제
"Uncaught Error: You are using a ServerProxy but have not supplied it with a url.".
을 내 QuizModel 필요한 내 REST API에 전달하는 프록시 만이로드가 있습니다 questions()는 기본 프록시를 사용하는 것으로 보입니다. 로드 매개 변수 (url과 필요한 api 키 포함)를 사용하여로드 호출을 구성하려고 시도했지만 작동하지 않습니다. 어떻게해야하는지에 대한 문서를 찾을 수없는 것 같아요. 대부분의 관련 게시물은 localstorage에 대해서만 이야기합니다. 도와주세요!
편집 : 내 질문 목록보기를 추가 :
BuddeMobile.views.QuestionList = Ext.extend(Ext.Panel, {
title: 'Quiz',
iconCls: 'quiz',
cls: 'question',
scroll: 'vertical',
initComponent: function(){
Ext.apply(this, {
dockedItems: [{
xtype: 'toolbar',
title: 'Quiz'
}],
items: [{
xtype: 'list',
itemTpl: '<div class="quiz-question">{prompt}</div>',
store: 'quizStore',
listeners: {
itemtap: function (list, index, el, e){
console.log('question tap',el);
}
}
}]
});
BuddeMobile.views.QuestionList.superclass.initComponent.call(this, arguments);
},
updateWithRecord: function(record) {
var toolbar = this.getDockedItems()[0];
toolbar.setTitle(record.get('category')); //works
var list = this.items.get(0);
console.log(record.questions()); //prints out mixed collection of questions
var question1 = record.questions().getAt(0); //testing
console.log(question1.answers()); //prints out mixed collection for first question's answers
list.update(record.questions()); //does not work. How can I populate the list??
}
});
당신은 내가 (내가 로그인시 저장소를로드로) 내가 필요한 데이터를 얻을 수 있습니다 볼 수 있습니다,하지만 난을 만드는 방법을 알고하지 않기 때문에 목록은 데이터의 하위 집합을 사용합니다. 업데이트 기능을 사용해 보았지만 많은 일을하지 못했습니다!
내가 가진 문제는 목록이 상점에 묶여 있다고 생각합니다. 내가 원하는 것을 목록에 표시 할 수없는 이유는 무엇입니까? 단일 저장소 사용에 대한 나의 옵션은 무엇입니까? – Burnzoire
로그인 한 학생의 모든 quizes, 질문 및 답변을 상점에 별도로로드 한 다음 퀴즈/질문을 선택했는지 여부에 따라 각 상점에 필터를 사용하도록 REST API를 재정렬했습니다. 큰 변화가 있지만 지금까지 효과가 있습니다! – Burnzoire
실제로이 3 개의 개별 상점에서 외래 키가 0으로오고 있으므로 내 필터가 작동하지 않습니다. grrrrrrrr – Burnzoire