如何在iOS平台上更新或刷新RadListView项目?

时间:2019-05-02 17:16:51

标签: nativescript nativescript-telerik-ui nativescript-plugin

我有一个RadListView,它从可观察对象数组获取数据,并将其内容显示为文本。 修改Observable Array中对象的值之一时,即使使用 radlist.refresh();

,RadListView也不会刷新或更新该值。

在Android:android:平台上,这不是问题,它可以正常工作并刷新,但在iOS平台上却没有。

这是我的XML代码

            ```<lv:RadListView items="{{ groceryList }}" id="marad" row="1" height="100%"
                itemSwipeProgressStarted="onSwipeCellStarted" swipeActions="true">

                <lv:RadListView.itemTemplate>
                    <GridLayout class="grocery-list-item">
                        <Label 
                        id="nameLabel" textWrap="true" class="p-15 radlist"    text="{{ 'ناو: ' + name + '\n' + ' بڕ: ' + quantity + '\n' + ' نرخی یەک دانە: ' + sellPrice }}" />

                    </GridLayout>
                </lv:RadListView.itemTemplate>
                         <lv:RadListView.headerItemTemplate>
                         <StackLayout>
          <Button class="btn btn-primary" text="خوێندنه‌وه‌ بە باڕکۆد" tap="barcodeSell"></Button>

 <Label class="page-placeholder" text="نرخی گشتی" textWrap="true"/>

<Label  

        text="0"
        id="totalprice" 
        textWrap="true"
        class="input input-border"/>

    <Button class="btn btn-primary" text="بفرۆشە" tap="tapSell"></Button>
 </StackLayout>
        </lv:RadListView.headerItemTemplate>

                <lv:RadListView.itemSwipeTemplate>
                                      <GridLayout columns="auto,  *, auto">


                        <GridLayout id="increase-view" col="2" tap="onIncrease"
                            class="increase-view">
                           <Label 
                            text="&#xf101;" class="fonticon duplic" /> 
                        </GridLayout>

                        <GridLayout id="delete-view" col="0" tap="onDelete"
                            class="delete-view">

                            <Label 
                            text="&#xf100;" class="fonticon duplic" /> 

                        </GridLayout>
                    </GridLayout>

                </lv:RadListView.itemSwipeTemplate>
            </lv:RadListView>```

这是我在JS中的“修改值”功能:

exports.onIncrease = function (args) {

  var item = args.view.bindingContext;
  var index = groceryList.indexOf(item);
  var totalPrice = groceryList.getItem(index).sellPrice;

  var element = groceryList.getItem(index);
  var quantity = groceryList.getItem(index);
  var quantity3 = quantity["quantity"];

  dialogs.prompt({

    message: "بڕی کاڵاکە دیاریبکە",
    okButtonText: "هەڵبژێرە",
    cancelButtonText: "داخە",


    inputType: dialogs.inputType.number
}).then(function (r) {


  if(r.result) {
  element["quantity"] = r.text;
  groceryList.setItem(index, element);

 sumPrice = (sumPrice - (Number(totalPrice)*Number(quantity3)));

  sumPrice =  sumPrice + (Number(r.text)*Number(totalPrice));

  label.text = sumPrice;

  radlist.refresh();
 }
  else {
    var rslt = false;
  }
});



};

以下是提供RadListView的代码:

function onNavigatingTo(args) {
    const page = args.object;
    label = page.getViewById("totalprice");
    const sideDrawer = app.getRootView();
    sideDrawer.gesturesEnabled = false;

    spanquantity = page.getViewById("quantbtn");

    groceryList = new ObservableArray([

    ]);
    pageData = observableModule.fromObject({
      groceryList: groceryList,

    });

    page.bindingContext = pageData;

    radlist = page.getViewById("marad");
     sumPrice = 0;


}
exports.onNavigatingTo = onNavigatingTo;

然后,如果输入的条形码已找到数据库,则将项目数据推送到Observable Array,但这与此问题无关,我说这些是为了使代码清晰。

还有一件事,如果我轻扫RadListView并点击“删除项目”按钮,它将删除该项目,因此,我猜如果是“删除”按钮,它将更新和刷新列表。

因此,此问题与增加项目数量的过程有关。

0 个答案:

没有答案