解析数值数据项返回NaN

时间:2016-08-08 01:08:50

标签: javascript jquery numbers jquery-data

我有以下HTML表格行数据(当然在正确的表格中(表格> tbody> tr)):

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace App7
{
    public sealed partial class MainPage : Page
    {

        public MainPage()
        {
            this.InitializeComponent();
        }
        DeviceInformationCollection DevicesFound;
        WiFiDirectAdvertisementPublisher pub;
        WiFiDirectConnectionListener listener;
        CancellationTokenSource m_CancellationTokenSource;
        private async void button_Click(object sender, RoutedEventArgs e)
        {
            String DeviceSelector = WiFiDirectDevice.GetDeviceSelector(WiFiDirectDeviceSelectorType.AssociationEndpoint);
            DevicesFound = await DeviceInformation.FindAllAsync(DeviceSelector);
            if(DevicesFound.Count>0)
            {
                connectedDeviceslist.ItemsSource = DevicesFound;
                var dialog = new MessageDialog(DevicesFound[0].Name);
                await dialog.ShowAsync();
            }
        }

        private async void button1_Click(object sender, RoutedEventArgs e)
        {
            int selectedIndex = connectedDeviceslist.SelectedIndex;
            String deviceID = DevicesFound[selectedIndex].Id;
            var selecetedDevice = DevicesFound[selectedIndex];
            try
            {
                WiFiDirectConnectionParameters connectionParams = new WiFiDirectConnectionParameters();
                connectionParams.GroupOwnerIntent = Convert.ToInt16("1");
                connectionParams.PreferredPairingProcedure = WiFiDirectPairingProcedure.GroupOwnerNegotiation;

                m_CancellationTokenSource = new CancellationTokenSource();
                var wfdDevice = await WiFiDirectDevice.FromIdAsync(selecetedDevice.Id, connectionParams).AsTask(m_CancellationTokenSource.Token);
                var EndpointPairs = wfdDevice.GetConnectionEndpointPairs();
            }
            catch(Exception ex)
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.High, async() =>
                {
                    var dialog = new MessageDialog(ex.Message);
                    await dialog.ShowAsync();
                });
            }




        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            pub = new WiFiDirectAdvertisementPublisher();
            pub.Advertisement.ListenStateDiscoverability = WiFiDirectAdvertisementListenStateDiscoverability.Normal;
            listener = new WiFiDirectConnectionListener();
            listener.ConnectionRequested += OnConnectionRequested;
            pub.Start();
        }
        private async void OnConnectionRequested(WiFiDirectConnectionListener sender, WiFiDirectConnectionRequestedEventArgs args)
        {
            try
            {
                var ConnectionRequest = args.GetConnectionRequest();

                var tcs = new TaskCompletionSource<bool>();
                var dialogTask = tcs.Task;
                var messageDialog = new MessageDialog("Connection request received from " + ConnectionRequest.DeviceInformation.Name, "Connection Request");

                // Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers 
                messageDialog.Commands.Add(new UICommand("Accept", null, 0));
                messageDialog.Commands.Add(new UICommand("Decline", null, 1));

                // Set the command that will be invoked by default 
                messageDialog.DefaultCommandIndex = 1;

                // Set the command to be invoked when escape is pressed 
                messageDialog.CancelCommandIndex = 1;

                await Dispatcher.RunAsync(CoreDispatcherPriority.High, async () =>
                {
                    // Show the message dialog 
                    var commandChosen = await messageDialog.ShowAsync();

                    tcs.SetResult((commandChosen.Label == "Accept") ? true : false);
                });

                var fProceed = await dialogTask;

                if (fProceed == true)
                {
                    var tcsWiFiDirectDevice = new TaskCompletionSource<WiFiDirectDevice>();
                    var wfdDeviceTask = tcsWiFiDirectDevice.Task;

                   // WriteToOutput("Connecting to " + ConnectionRequest.DeviceInformation.Name + "...");

                    WiFiDirectConnectionParameters ConnectionParams = new WiFiDirectConnectionParameters();

                    await Dispatcher.RunAsync(CoreDispatcherPriority.High, async () =>
                    {
                        try
                        {
                            ConnectionParams.GroupOwnerIntent = 14;
                            tcsWiFiDirectDevice.SetResult(await WiFiDirectDevice.FromIdAsync(ConnectionRequest.DeviceInformation.Id, ConnectionParams));
                        }
                        catch (Exception ex)
                        {
                           // WriteToOutput("FromIdAsync task threw an exception: " + ex.ToString());
                        }
                    });

                    WiFiDirectDevice wfdDevice = await wfdDeviceTask;

                    var EndpointPairs = wfdDevice.GetConnectionEndpointPairs();

                   /* m_ConnectedDevices.Add("dummy", wfdDevice);

                    WriteToOutput("Devices connected on L2, listening on IP Address: " + EndpointPairs[0].LocalHostName.ToString() + " Port: " + Globals.strServerPort);

                    StreamSocketListener listenerSocket = new StreamSocketListener();
                    listenerSocket.ConnectionReceived += OnSocketConnectionReceived;

                    await listenerSocket.BindEndpointAsync(EndpointPairs[0].LocalHostName, Globals.strServerPort);*/
                }
                else
                {
                  /*  // Decline the connection request
                    WriteToOutput("Connection request from " + ConnectionRequest.DeviceInformation.Name + " was declined");

                    ConnectionRequest.Dispose();*/
                }
            }
            catch (Exception ex)
            {
                //WriteToOutput("FromIdAsync threw an exception: " + ex.ToString());
            }
        }
    }
    }

和以下jquery代码循环遍历现有行,并根据价格找到插入新行的位置(表按价格排序):

<tr id="uo_311" data-id="311" data-price="250.01111100" data-qty="1.00000000" data-value="250.26112211">
  <td>....</td>
  ....
</tr>

这个基本逻辑似乎工作正常,但出于某种原因声明

var price = parseFloat(response['price']);
var elTable = $('#openTable');
var tableRowCount = elTable.find('tbody > tr').length;
for (var i = 0; i < tableRowCount; i++) {
    var row      = elTable.find("tbody > tr").eq(i);
    var rowPrice = parseFloat(row.data('price'));
    if (price > rowPrice) {
        row.before('<tr><td>NEW ROW</td></tr>');
        break;
    }
 }

返回NaN。有没有人知道我在这里做错了什么?

0 个答案:

没有答案