안녕하세요 다음 상황이 있습니다. 한 블록에 with
블록이 지정되었습니다. 이 속성이 null이면 내용이 존재하지 않습니다. 그러나 속성을 넣을 때 마크 업을 생성해야합니다.녹아웃이 값을 바인딩하지 않습니다.
HTML :
<!-- ko with: Gallery -->
<div class="GalleryMain">
<a href="#" data-bind="attr: {href: Current.Zoomed}" class="cloud-zoom" id="TargetZoom">
<img data-bind="attr: {src: Current.Main}" alt="" />
</a>
<span data-bind="text: Current.Zoomed"></span>
<span data-bind="text: Current.Main"></span>
</div>
<!-- /ko -->
<a href="javascript:;" id="Do">Update property</a>
자바 스크립트 :
function PrimaryViewModel() {
var self = this;
this.Gallery = ko.observable(null);
this.Exit = function() {
self.Gallery(null);
}
}
var Picture = (function() {
function _Constructor(input) {
this.Zoomed = ko.observable(input.Zoomed);
this.Main = ko.observable(input.Main);
this.Thumb = ko.observable(input.Thumb);
}
_Constructor.Width = 489;
_Constructor.Height = 835;
return _Constructor;
})();
function GalleryViewModel(data, current) {
var self = this;
this.Pictures = ko.observableArray($.map(data, function(input) {
return new Picture(input);
}));
var all = this.Pictures();
this.Current = ko.observable(all[0]);
for (var i = 0; i < all.length; i++)
if (all[i].Main == current)
this.Current(all[i]);
this.SetCurrent = function() {
self.Current(this);
}
}
$(function() {
var viewModel = new PrimaryViewModel();
$("#Do").click(function() {
var data = [{
"Zoomed": "Content/Big/1Z.jpg",
"Main": "Content/Big/1.jpg",
"Thumb": "Content/Images/Thumbs/1.jpg"},
{
"Zoomed": "Content/Big/2Z.jpg",
"Main": "Content/Big/2.jpg",
"Thumb": "Content/Images/Thumbs/2.jpg"},
{
"Zoomed": "Content/Big/3Z.jpg",
"Main": "Content/Big/3.jpg",
"Thumb": "Content/Images/Thumbs/B1.jpg"},
{
"Zoomed": "Content/Big/4Z.jpg",
"Main": "Content/Big/4.jpg",
"Thumb": "Content/Images/Thumbs/3.jpg"},
{
"Zoomed": "Content/Big/15.jpg",
"Main": "Content/Big/5.jpg",
"Thumb": "Content/Images/Thumbs/B2.jpg"}];
viewModel.Gallery(new GalleryViewModel(data, "Content/Big/1.jpg"));
});
ko.applyBindings(viewModel);
});
html로 생성되는 Update property
버튼을 누른 후하지만 바인딩이 발생하지 않습니다. 도와주세요.
여기서 가장 큰 문제는 'Current'속성에 액세스 할 수 없다는 것입니다. 데모에서는'img' 태그의 렌더링이 없습니다. – Oybek
어쨌든 당신의 노력에 감사드립니다.)) – Oybek