viewmodel (observable) 클래스 생성자에서 정의 된 로컬 값에 대해이 작업 예제가 있지만 원격 데이터 소스가있을 때 작동하지 않는 것처럼 보입니다. Kendo, MVVM 텍스트를 바인딩하는 방법 : 필드를 원격 DataSource에 바인딩 하시겠습니까?
가 어떻게 원격 데이터 소스에 대한 작업을 아래와 같은 예를 얻을 수, 심지어는 가능하다?<div id='root'>
<label>Remote Name: </label>
<span data-bind="text: firstName"><!--firstName--></span>,
<span data-bind="text: lastName"><!--lastName--></span>
<div>
<label>Remote Name:
<input data-bind="value: firstName" />,
<input data-bind="value: lastName" />
</label>
</div>
</div>
<br/>
<br/>
<div id='local-root'>
<label>Local Name: </label>
<span data-bind="text: firstName"></span>,
<span data-bind="text: lastName"></span>
<div>
<label>Local Name:
<input data-bind="value: firstName" />,
<input data-bind="value: lastName" />
</label>
</div>
</div>
<br/>
<br/>
<div id='test-ajax'>
<pre>
</pre>
</div>
$(document).ready(function(){
/**
* #local-root example, binds to local data like in the examples
*/
var personLocalViewModel = kendo.observable({
firstName: 'James',
lastName: 'Taylor'
});
kendo.bind($('#local-root'), personLocalViewModel);
/**
* set's up a mock api endpoint for jquery and other libraries
*/
$.mockjax({
url: "js/data/person.json",
contentType: "application/json",
responseText: {
firstName: 'James',
lastName: 'Taylor'
}
});
/**
* test-ajax - proves mockajax works
*/
$.ajax({
url: "js/data/person.json",
dataType:'json',
success:function(response){
$('#test-ajax pre').text(JSON.stringify(response));
}
});
/**
* #root or remote-root, this dataSource is not bidning to the html, why?
*/
console.log('KENDO.js', kendo.data);
var personSource = new kendo.data.DataSource({
transport: {
read: {
url: "js/data/person.json",
dataType: "json"
}
},
schema:{
parse: function(response){
console.log('personSource.schema.parse',response);
return response;
},
data: function(response){
console.log('personSource.schema.data',response);
return response;
}
}
});
//would this work?
var personViewModel = kendo.observable({
dataSource: personSource
});
//would this work?
var personViewModel2 = kendo.observable(personSource);
kendo.bind($('#root'), personViewModel);
});
당신은 어떤 행운이 있었나요 내 해결책? – ryan