Marionette/Backbone을 사용하고 있고 여러 객체가있는 JSON 파일이 있으므로이 JSON 파일의 항목으로 선택 상자를 채워야합니다. 따라서 accountType, states 및 dates의 드롭 다운 상자.드롭 다운 상자에서 사용할 JSON 파일을 분할하는 방법
현재 accountType 만 신경 쓰고 있지만 드롭 다운에 "전체"또는 "평가판"만 표시되도록 JSON 파일을 분할하는 방법을 찾을 수 없습니다.
를 - 난과 같이 파일 내의 .js에 액세스 내가 JSON이 내가 사용할 필요가 무엇 파일을 작성하지 않은{
"accountType":["Full","Trial"],
"states": [{"state":"AL","stateDescription":"Alabama","featured":"A1"},
{"state":"AK","stateDescription":"Alaska","featured":"B1"}],
"dates":[{"dateDescription":"Jan","month":1,"year":2008},
{"dateDescription":"Feb","month":2,"year":2008}]
}
:
나는이와 비슷한 JSON 파일이
initialize: function() {
this.on('change', this.change);
var that = this;
$.getJSON("webapp/jsondata", function (data) {
that.set('accountType', data);});
}
그러나 다운 상자 내 드롭 기본적으로 내가 얻을 : 형식의 종류에
Full, Trial
[object Object], [object Object]
합니다.
나는 왜 JSON 파일을 나눠 쓰지는 않지만 단지 어떻게해야 하는지를 이해할 수 있다고 생각한다. 온라인으로 페이지와 페이지를 읽지 만 아무 것도 적절하지 않은 것 같습니다.
감사합니다. 친절하게 대해주십시오.
편집 : ---
다음은 백본 데이터의 전체 코드입니다. 이것은 이제 accountType 상자를 채우기 위해 작동하지만 다른 드롭 다운으로 복제 할 때 모두 공백으로 바뀝니다.
define([ 'backbone', 'underscore', 'vent', ], function (Backbone, _, vent) {
'use strict';
return Backbone.Model.extend({
url: {},
loaded: false,
defaults: {
accountType: [],
states: [],
dates: [],
},
initialize: function() {
this.on('change', this.change);
var that = this;
$.getJSON("webapp/jsondata", function (data) {
that.set({
states: data.states,
});
});
$.getJSON("webapp/jsondata", function (data) {
that.set({
dates: data.dates,
});
});
$.getJSON("webapp/jsondata", function (data) {
that.set({
accountType: data.accountType,
});
});
},
});
});
나는 "상태가"주, 설명이하고 특색있는 동안 ACCOUNTTYPE 만 한 특성을 가지고 있기 때문에 그것의 같은데요. 예를 들어 "AL"과 "AK"만을 고르고 싶습니다. 그래서 내 데이터를 슬라이스 (내가 생각하는) 및 드롭 다운에 할당하는 방법이 필요합니다.
define([ 'marionette', 'templates', 'vent', 'select'],
function (Marionette, templates, vent, select) {
"use strict";
return Marionette.ItemView.extend({
template: templates.inputView,
serializeData: function() {
return {
states: this.options.meta.get('states'),
dates: this.options.meta.get('dates'),
accountType: this.options.meta.get('accountType'),
};
},
});
});
', data);}); 정확히 무슨 일이 생기는지는 알지 못한다. (어떤 종류/형식의 데이터가 받아 들여지고 있는지) –
당신은 데이터를 사용해 보았습니까? 마지막 줄의 스크립트에서 data.Trial을 사용 했습니까 ?? –
(backbones 메타 데이터 모델에서) accountType 배열을 프로파일 데이터로 설정해야합니다. 문제는 JSON 파일의 모든 것을 가져 오는 것입니다. 두 가지 accountType 옵션 만이 아닙니다. – Hagbard