C# 未捕获错误:无法分析绑定;消息:ReferenceError:xxx未定义;
这是我第一次使用Knockout.js 我不明白我为什么会有这个问题 未捕获错误:无法分析绑定。 消息:ReferenceError:未定义DataPrevista; 绑定值:value:DataPrevista,namePath:true 我希望有人能帮助我 这是我的代码: 看法C# 未捕获错误:无法分析绑定;消息:ReferenceError:xxx未定义;,c#,asp.net-mvc,knockout.js,C#,Asp.net Mvc,Knockout.js,这是我第一次使用Knockout.js 我不明白我为什么会有这个问题 未捕获错误:无法分析绑定。 消息:ReferenceError:未定义DataPrevista; 绑定值:value:DataPrevista,namePath:true 我希望有人能帮助我 这是我的代码: 看法 @LabelFor(model=>model.Cliente) @Html.DropDownListFor(model=>model.Cliente.Codigo,新选择列表(model.clientesselec
@LabelFor(model=>model.Cliente)
@Html.DropDownListFor(model=>model.Cliente.Codigo,新选择列表(model.clientesselectionavis,“Value”,“Text”,model.Cliente),新{@class=“form control”})
@LabelFor(model=>model.Funcionario)
@Html.DropDownListFor(model=>model.Funcionario.Codigo,新选择列表(model.funcionariosselecionavis,“Value”,“Text”,model.client),新{@class=“form control”})
阿根达曼托斯酒店
@EditorFor(model=>model.Agendamentos)
@ActionLink(“列表”、“索引”)
编辑器模板
<div>
@Html.LabelFor(model => model.DataPrevista)
</div>
<div>
@Html.TextBoxFor(model => model.DataPrevista, new { @class = "form-control", data_bind = "value: dataPrevista, namePath: true" })
</div>
<div>
@Html.LabelFor(model => model.InicioPrevisto)
</div>
<div>
@Html.TextBoxFor(model => model.InicioPrevisto, new { @class = "form-control", data_bind = "value: inicioPrevisto, namePath: true" })
</div>
<div>
@Html.LabelFor(model => model.FimPrevisto)
</div>
<div>
@Html.TextBoxFor(model => model.FimPrevisto, new { @class = "form-control", data_bind = "value: fimPrevisto, namePath: true" })
</div>
<div>
@Html.LabelFor(model => model.TrasladoPrevisto)
</div>
<div>
@ Html.TextBoxFor(model => model.TrasladoPrevisto, new { @class = "form-control", data_bind = "value: trasladoPrevisto, namePath: true" })
@LabelFor(model=>model.DataPrevista)
@Html.TextBoxFor(model=>model.DataPrevista,新{@class=“form control”,data_bind=“value:DataPrevista,namePath:true”})
@LabelFor(model=>model.ini)
@TextBoxFor(model=>model.inicioprovisto,新的{@class=“formcontrol”,data_bind=“value:inicioprovisto,namePath:true”})
@LabelFor(model=>model.FimPrevisto)
@Html.TextBoxFor(model=>model.FimPrevisto,新{@class=“form control”,data_bind=“value:FimPrevisto,namePath:true”})
@LabelFor(model=>model.TrasladoPrevisto)
@Html.TextBoxFor(model=>model.TrasladoPrevisto,新{@class=“form control”,data_bind=“value:TrasladoPrevisto,namePath:true”})
Javascript
<script type="text/javascript" language="javascript">
function createViewModel() {
var createAgendamento = function () {
return {
dataPrevista: ko.observable(),
inicioPrevisto: ko.observable(),
fimPrevisto: ko.observable(),
trasladoPrevisto: ko.observable()
};
};
var addAgendamento = function () {
agendamentos.push(createAgendamento());
};
var removeAgendamento = function () {
agendamentos.pop();
};
var cliente = ko.observable();
var funcionario = ko.observable();
var agendamentos = ko.observableArray([createAgendamento()]);
return {
cliente: cliente,
funcionario: funcionario,
agendamentos: agendamentos,
addAgendamento: addAgendamento,
removeAgendamento: removeAgendamento
};
}
$(document).ready(function () {
var viewModel = createViewModel();
ko.applyBindings(viewModel);
});
函数createViewModel(){
var createAgendamento=函数(){
返回{
dataPrevista:ko.observable(),
inicioPrevisto:ko.observable(),
fimPrevisto:ko.可观察(),
trasladoPrevisto:ko.observable()
};
};
var addAgendamento=函数(){
push(createAgendamento());
};
var removagendamento=函数(){
agendamentos.pop();
};
var cliente=ko.可观察();
var funcionario=ko.observable();
var agendamentos=ko.observearray([createAgendamento()]);
返回{
客户:客户,
Functionario:Functionario,
阿根达曼托斯:阿根达曼托斯,
addAgendamento:addAgendamento,
removeAgendamento:removeAgendamento
};
}
$(文档).ready(函数(){
var viewModel=createViewModel();
应用绑定(视图模型);
});
您的数据语法似乎不正确。它应该是
数据绑定
而不是数据绑定
请参阅淘汰文档:
另外,dataPrevista
是视图模型中的嵌套可观察对象,因此您需要像这样引用它
data-bind="value: agendamentos.dataPrevista"
错误消息非常清楚:“DataPrevista未定义”。因此,在html中的某个地方有一个绑定
data bind=“value:DataPrevista”
,但javascript viewmodel没有这个属性。但是,在您问题中的代码中有DataPrevista
,因此您发布了错误的代码。。。所以没有人会告诉你如何解决这个问题。对不起,我发错代码了。
data-bind="value: agendamentos.dataPrevista"