function tournamentViewModel(){
var self= this;
self.name = ko.observable();
self.districts = ko.observableArray([new district('Provo',1),new district('Salt Lake City',2),new district('St. George',3)]);
self.district = ko.observableArray();
self.regions = ko.observableArray([new region('Utah',1),new region('Idaho',2)]);
self.region = ko.observableArray();
self.location = ko.observable();
self.date = ko.observable();
self.startTime = ko.observable();
self.image = ko.observable();
self.flyer = ko.computed(function(){return '<h1>'+self.name+'</h1>'+self.image},self);
self.clearImage = function(){
self.image('');
}
self.tournamentID = ko.computed(function(){return 't_'+self.district+'_'+self.region+'_'+self.date}, self);
};
上面的 knockout.js 视图模型似乎很好,除非我想将某些东西绑定到计算的 observable flyer
。相反,我看到的只是以下文本:
<h1>function c(){if(0<arguments.length){if(!c.equalityComparer||!c.equalityComparer(d,arguments[0]))c.I(),d=arguments[0],c.H();return this}a.U.La(c);return d}</h1>function c(){if(0<arguments.length){if(!c.equalityComparer||!c.equalityComparer(d,arguments[0]))c.I(),d=arguments[0],c.H();return this}a.U.La(c);return d}
我不知道这里发生了什么。下面是我应用它的绑定。我已经尝试过 html 和文本绑定。
<span data-bind="text: flyer"></span>
顺便说一句,计算出的 observabletournamentID
效果很好,语法似乎相同。我认为当我self.name
在计算的 observable 中使用时会出现问题。有任何想法吗?