When c.server.update() is called, the value of "data.num" will be passed to server side.
In server side script, call "input.num" can get the value of "data.num".
Client Script
- Everything from the server’s data object can be accessed via c.data or $scope.data.
- If you change a value in the data model, use server.update() to post the entire data object to the server script as input. Note: After calling server.update() the client script’s data object is automatically overwritten with the server’s data object.
- Use c.options or scope.options to see what values were used to invoke the widget. This object is read-only and making changes will not be visible in the server script.
Note: Only client scripts set with the UI type as Both or Mobile run in Service Portal.
Server Script
- An empty data object is initialized.
- Use the input or options objects to get any data that was sent from the client controller or used to initialize the widget from the server.
- After the server script executes, the data object is json serialized and sent to the client controller.
html template
<div>
<!-- your widget template -->
<input type="text" ng-model="c.data.num"
ng-change="c.update()"
ng-model-options="{debounce: 250}"
/>{{c.data.num}}<br><br>
<li class="list-group-item" ng-repeat="item in c.data.items">
<a href="javascript:void(0)">{{item.name}}</a><span class="pull-right">{{item.price}}</span>
</li>
</div>
client script
function() {
var c = this;
c.update = function() {
c.server.update().then(function(r) {
alert(r.a); // return from server script
});
};
}
server script
(function() {
data.items = [];
var a = input.num;
if(!a)
{
a = 1;
}
data.a = a;
for( var i =0;i<a;i++)
{
data.items.push({name:'name '+i,price:i});
}
})();
沒有留言:
張貼留言