This is a migrated thread and some comments may be shown as answers.

Programmatic template binding with source

3 Answers 154 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Neeraj
Top achievements
Rank 1
Veteran
Neeraj asked on 21 Sep 2017, 10:08 AM
Hello,
1) have where and external template are   The is bind to that The script inside template has div with no data-bind specified. In want to make ajax call to get data source and bind that data to  how to do that, since new data is not part of viewModel?

2) if we specify kendo.bind() statement in javascript we  need to write data-bind="source: x" in div attribute right? either one of them should be written or both are
        

3 Answers, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 25 Sep 2017, 07:49 AM
Hi Neeraj,

As far as I can understand, you have a scenario, in which a Template is defined for an element. Initially, the parent element has no source bound and the data is loaded later with an AJAX call. If this is the case, you will need to pass the data from that call to a property in the ViewModel:
clickToMakeAjax: function() {
  var that = this;
  $.get(url, function(data) {
    that.set('data', data);
  }, "jsonp");       
}

Here you will find a simple implementation of the above suggestion.

Concerning the second question, in order to successfully bind a source to an element, you will need to use both data-bind="source:..." and kendo.bind(..., ...).

Further information on source binding in Kendo MVVM could be found in our Documentation.

Regards,
Veselin Tsvetanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Neeraj
Top achievements
Rank 1
Veteran
answered on 03 Oct 2017, 03:43 AM
Hello, if there is no value in ViewModel for property, what would be way to set it as 'new Array()' or 'null' in javascript?
 
0
Dimitar
Telerik team
answered on 04 Oct 2017, 01:21 PM
Hello Neeraj,

The model property can be updated by using the ObservableObject's set() method as follows:
<script>
   observable.set("data", null);
</script>


Here is a Dojo example that demonstrates the above.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
MVVM
Asked by
Neeraj
Top achievements
Rank 1
Veteran
Answers by
Veselin Tsvetanov
Telerik team
Neeraj
Top achievements
Rank 1
Veteran
Dimitar
Telerik team
Share this question
or