가 나는 JS 오류가 "catch되지 않은 구문 에러 : 예기치 않은 토큰 &"나는MVC 뷰 모델> JS 뷰 모델 - catch되지 않은 구문 에러 : 예기치 않은 토큰 및
(knockout.js에 대한) 내 서버 측 뷰 모델에서 클라이언트 측의 ViewModel을 통과 할 때 뷰 모델
public class InvoiceViewModel
{
public Factuur Factuur { get; set; }
public List<Factuurlijn> Factuurlijnen { get; set; }
}
컨트롤러
//Create Viewmodel
InvoiceViewModel ivm = new InvoiceViewModel();
//Initialize vm objects
int aantaldagentotvervaldatum = Convert.ToInt32(General.getParameter("defaultaantaldagentotvervaldatum"));
Factuur i = new Factuur { factuur_nummer = 1, factuur_nummervoorvoegsel = DateTime.Now.Year.ToString(), factuur_datum = DateTime.Now, factuur_type = Ftype, factuur_vervaldatum = DateTime.Now.AddDays(aantaldagentotvervaldatum), factuur_kortingspercentage = Convert.ToDecimal(General.getParameter("defaultkortingspercentage")) };
List<Factuurlijn> FLijnen = new List<Factuurlijn>{new Factuurlijn(){ factuurlijn_aantal = 0, factuurlijn_item="", factuurlijn_prijs=0 }};
// add objects to viewmodel
ivm.Factuur = i;
ivm.Factuurlijnen = FLijnen;
return View(ivm);
보기
@{
//prepare viewmodel to assign to pas into js
string initialData = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Model);
}
...
<script type="text/javascript">
var initialDataJS = @(initialData)
alert('initialdata : ' + initialDataJS);
</script>
내 경고가 표시되지 않으며 오류가 발생합니다. 크롬 : //firebug/content/net/requestObserver.js 크롬에서
: catch되지 않은 구문 에러 클리어 된 범위 Bronbestand 갈 컴파일 및 스크립트를 실행하는 시도 : FF에서
: 예기치 않은 난을 벌써 나는 내가 JS 변수에 할당하기 전에는 뷰 모델의 직렬화에 잘못,하지만 난 이유를 이해하지 않는 느낌이있다 &
...
토큰
var initialDataJS = {"Factuur":{"factuur_id":0,"factuur_nummervoorvoegsel":"2012","factuur_nummer":1,"factuur_type":"F","bedrijf_id":0,"factuur_naam":null,"factuur_notities":null,"factuur_details":null,"factuur_datum":"\/Date(1335443889648)\/","factuur_vervaldatum":"\/Date(1336307889648)\/","factuur_kortingspercentage":0,"factuur_betaald":false,"factuur_bedrijf_naam":null,"factuur_bedrijf_adres":null,"factuur_bedrijf_postcode":null,"factuur_bedrijf_gemeente":null,"factuur_bedrijf_land":null,"factuur_bedrijf_tel":null,"factuur_bedrijf_fax":null,"factuur_bedrijf_gsm":null,"factuur_bedrijf_email":null,"factuur_bedrijf_website":null,"factuur_bedrijf_btw":null,"factuur_deleted":false,"bedrijf":null,"bedrijfReference":{"Value":null,"EntityKey":null,"RelationshipName":"ScotaModel.facturen_ibfk_1","SourceRoleName":"facturen","TargetRoleName":"Bedrijf","RelationshipSet":null,"IsLoaded":false},"factuurlijnen":[],"EntityState":1,"EntityKey":null},"Factuurlijnen":[{"factuurlijn_id":0,"factuur_id":0,"factuurlijn_item":"","factuurlijn_aantal":0,"factuurlijn_prijs":0,"factuurlijn_btwbedrag":0,"factuurlijn_btwpercentage":0,"factuurlijn_datum":"\/Date(-62135596800000)\/","factuurlijn_volgorde":null,"factuurlijn_deleted":false,"facturen":null,"facturenReference":{"Value":null,"EntityKey":null,"RelationshipName":"ScotaModel.factuurlijnen_ibfk_1","SourceRoleName":"factuurlijnen","TargetRoleName":"facturen","RelationshipSet":null,"IsLoaded":false},"EntityState":1,"EntityKey":null}]}
누군가가 나를 도울 수 유효하지 않은 속성 ID : y를 누른 후, 나는 내 JS 오류가
오류 이것을보고 ...
string initialData = Json.Encode(Model);
하지만 성공을 했어요?
내 모델을 작성하는 데 실수를했다고 생각합니다. invoicelines는 별도로 대신 인보이스 개체 바로 아래에 있어야했습니다. 하지만 이제는 "순환 참조가 객체 X.Models.Factuur를 직렬화하는 동안 감지되었습니다" – tortuga
흠, 좋지 않습니다. 일대 다 관계가 정의 될 때 한쪽 객체는 모든 많은 측면 객체의 집합을 포함하고 동시에 많은 측면 객체는 관련된 한쪽 객체에 대한 포인터를 가지기 때문에 EF로 자동 생성 된 객체를 직렬화 할 수 없습니다. 이것은 원형 참조 father-> collection-> son object-> father를 생성합니다. 순환 참조가 들어있는 객체 그래프를 직렬화 할 수 없습니다. 직렬화가 작동하려면 오브젝트 그래프가 트리가되어야합니다. 이것은 일반적으로 View에 전달 된 모든 객체에 대한 좋은 방법입니다. – tortuga
문제에 대한 해결책을 찾아 냈습니까? –