嗨,我正在尝试使用 observableArray 进行 foreach,我得到:
Uncaught Error: Unable to parse bindings.
Message: ReferenceError: Nome is not defined;
Bindings value: text: Nome
这是我的 HTML:
<table data-bind="foreach: funcionarios">
<tr>
<p>Nome: <span data-bind="text: Nome"></span></p>
<p>Apelido: <span data-bind="text: Apelido"></span></p>
<p>Hobby: <span data-bind="text: Hobby"></span></p>
<p>Função: <span data-bind="text: Funcao"></span></p>
<p>Ramal: <span data-bind="text: Ramal"></span></p>
<p>Email: <span data-bind="text: Email"></span></p>
<p>Celular: <span data-bind="text: Celular"></span></p>
<p>Aniversário: <span data-bind="text: Aniversario"></span></p>
</tr>
</table>
这是我的JS:
var FuncionarioViewModel = function () {
var me = this;
function Funcionario(base, id, nome, apelido, hobby, funcao, ramal, email, celular, aniversario) {
var me = this;
me.Id = id;
me.Nome = ko.observable(nome);
me.Apelido = ko.observable(apelido);
me.Hobby = ko.observable(hobby);
me.Funcao = ko.observable(funcao);
me.Ramal = ko.observable(ramal);
me.Email = ko.observable(email);
me.Celular = ko.observable(celular);
me.Aniversario = ko.observable(aniversario);
};
me.funcionarios = ko.observableArray([]);
me.add = function (id, nome, apelido, hobby, funcao, ramal, email, celular, aniversario) {
me.funcionarios.push(new Funcionario(me, id, nome, apelido, hobby, funcao, ramal, email, celular, aniversario));
};
}
var viewModel = new FuncionarioViewModel();
ko.applyBindings(viewModel);
这是小提琴链接:http: //jsfiddle.net/Lrqeb/8/
我不想使用该数组中的默认数据加载页面。