Transfer variable to another view

I declare a global variable in my config.js file :

var  _StockClass = 0;

Then I set its value from a view like this :

function GetListItem(e) {
    // alert('Click for Id=' + itemData.Id.toString() + ', Name=' + itemData.Name);
    _StockClass = e.StockClassID.toString();

}

And the View code :

<div data-options="dxView : { name: 'ProductClass', title: 'Products', pane: 'master' } " >
  <div  data-options="dxContent : { targetPlaceholder: 'content' } " >             
    <div data-bind="dxTextBox: { onValueChanged: onSearchTextChanged, mode: 'search' }"></div>
    <div data-bind="dxList: { dataSource: dataSource, pullRefreshEnabled: true, itemClickAction: GetListItem }">
      <div data-bind="dxAction: '#StockTypeViews/{StockClassID}'" data-options="dxTemplate : { name: 'item' } " >
        <!--
           <img height="55" style="padding: 10px; float:left;" data-bind="attr: { src: imageUrlPropertyName }" />
        -->
        <div class="list-item" data-bind="text: 'Code:' + ' ' + Code()"></div>
        <div class="list-item" data-bind="text: 'Description:' + ' ' + Description()"></div>
        <div class="list-item" data-bind="text: 'StockClassID:' + ' ' + StockClassID()" style="visibility:hidden"></div>
      </div>                  
    </div>
  </div>
</div>

Now, on the view I want to use it on I say :

dataSource = new DevExpress.data.DataSource({
    store: Prosound.db.StockTypeViews,
    map: function(item) {
        return new Prosound.StockTypeViewViewModel(item);
    },
    filter: [['StockClassID', '=', _StockClass], 'and', ['Active', '=', true]]
    //  searchExpr: 'StockID' //change field here for search
});

I have debugged and it keeps saying _StockClass is 0 .

How do I set its value in a view, and transfer it to another view?


Keep your datasource code in onDeviceReady Event which will wait for your view to load. and to pass the variable to another view ... declare your variable as global in app.config.js.

链接地址: http://www.djcxy.com/p/31104.html

上一篇: Angular和DevExtreme

下一篇: 将变量转移到另一个视图