亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 nativescript javascript 中從遠程 php 檢索多個數據?

如何在 nativescript javascript 中從遠程 php 檢索多個數據?

PHP
智慧大石 2022-07-16 16:14:36
我正在嘗試從我的遠程 php 文件中檢索多個數據并動態顯示它們,我通常在編寫 cordova 時使用 jquery 來執行此操作。我現在正在使用nativescript。這是我之前使用的 jquery 代碼$.getJSON(serviceURL + 'getroutes.php?station='+station, function(data) {        employees = data.items;        $.each(employees, function(index, employee) {            $('#employeeList').append('<li>'+                    '<img src="js/citybus.png" class="list-icon"/>' +                    '<p class="line1">' + employee.firstName + '</p>' +                    '<p class="line2">' + difference + ' Out' + '</p>' +                    '<p class="line3" style="color:'+ color +';margin-left:60px">' + SeatsLeft + ' seats left </p>' +                    '<button style="display:'+ display +'" class="bubble" data-difference="' + hoursMin + '" data-route="' + employee.firstName + '" data-busnum="' + employee.lastName + '" onclick="bookSeat(this);">' + '<center><img src="js/seat.jpg" style="height:15px;width:15px;"/></center>' + '</button>'                    + '<button data-id="' + employee.id + '" data-diff="' + hoursMin + '" data-name="' + employee.firstName + '" class="bubble" style="margin-right:30px" onclick="setReminder(this);">' + '<center><img src="js/bell.png" style="height:15px;width:15px;"/></center>' + '</button></li>');            if(index && index % 4 === 0) {                $('#employeeList').append('<center><div class="adSpace2" style="margin-top:2.5px;margin-bottom:2.5px;">'+'</div></center>');            }        });        setTimeout(function(){            scroll.refresh();        });    });請問我如何用nativescript做到這一點?
查看完整描述

1 回答

?
子衿沉夜

TA貢獻1828條經驗 獲得超3個贊

您需要使用Fetch API。


const Observable = require('tns-core-modules/data/observable').Observable

const model = new Observable()


function loaded(args) {

    args.object.bindingContext = model

    fetch(serviceURL + 'getroutes.php?station='+station).then(res => model.set('employees', res.items))

}

exports.loaded = loaded

然后在您的視圖 XML 中:


<Page xmlns="http://www.nativescript.org/tns.xsd" xmlns:lv="nativescript-ui-listview" aloaded="loaded">

    <StackLayout>

        <ListView items="{{employees}}">

            <Label class="line1" text="{{firstName}}" />

        </ListView>

    </StackLayout>

</Page>


查看完整回答
反對 回復 2022-07-16
  • 1 回答
  • 0 關注
  • 125 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號