2011-12-09 2 views
0

Silverlight에서 Knockout.js로 바뀝니다.보기 모델에서 사용자 지정 개체 사용 넉 아웃

public class MyViewModel : ViewModel 
{ 
    private MyCustomClass custom = null; 
    public MyCustomClass Custom 
    { 
    get { return custom; } 
    set { custom = value; 
     NotifyPropertyChanged("MyCustomClass"); 
    } 
    } 
} 

<TextBox Text="{Binding Path=Custom.PropertyName, Mode=TwoWay}" /> 

그러나, 나는 Knockout.js에서 같은 종류의 문제를 수행하는 방법을 잘 모르겠어요 : 나는 실버 라이트에 ViewModels를 만들 것이다 때, 나는 종종 이런 식으로 뭔가를 할 것이다. 현재, 내가 가진 :

<input type="text" data-bind="value:propertyName" /> 

var viewModel = { 
    custom: { 
    propertyName:"" 
    } 
} 

답변

1

당신은 확실히 당신이 가지고있는 무엇을 할 수 있지만, 당신은 당신이 이미 KO 1.3 바인딩 템플릿 또는 with를 사용하여 custom에 컨텍스트를 변경하지 않은 value: custom.propertyName에 바인딩 할 것입니다.

var Person = function(first, last) { 
    this.first = ko.observable(first); 
    this.last = ko.observable(last); 
}; 

var viewModel = { 
    people: ko.observableArray([ 
    new Person("Bob", "Smith"), 
    new Person("Ted", "Jones") 
    ]) 
}; 
:

이 작업을 수행하는 일반적인 방법은 같은 사용자 정의 개체에 대한 생성자 함수를 만드는 것입니다