将值从字符串设置为数字

时间:2018-08-01 14:59:09

标签: javascript react-native

我正在使用React-native和 // Creates a TFS test run public static void CreateTestRun(ITestPlan testPlan, int testCaseId, string testResult, string buildIdStr, string releaseUri, string releaseEnvironmentUri, string testRunName) { // --------------------------------Biuld the RunCreateModel for the test run:------------------------------------------------ // Find the test points of the current test case List<int> testPointIds = new List<int>(); ITestPointCollection testPoints = testPlan.QueryTestPoints("SELECT * FROM TestPoint WHERE testPoint.TestCaseId='" + testCaseId + "'"); foreach (ITestPoint testPoint in testPoints) { testPointIds.Add(testPoint.Id); } int buildId; int.TryParse(buildIdStr, out buildId); // Init RunCreateModel: RunCreateModel runCreateModel = new RunCreateModel( name: testRunName, startedDate: DateTime.Now.ToString("M/d/y h:m:s tt"), plan: new ShallowReference(id: testPlan.Id.ToString()), pointIds: testPointIds.ToArray(), buildId: buildId, releaseUri: releaseUri, releaseEnvironmentUri: releaseEnvironmentUri ); // ---------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------Create test run in progress-------------------------------------------- TestManagementHttpClient testManagementClient = new TestManagementHttpClient(new Uri(TFS_COLLECTION_NAME), new VssCredentials()); // Use RunCreateModel to create a test run on TFS (using the extended API): TestRun testRunExtended = testManagementClient.CreateTestRunAsync(runCreateModel, TFS_TEAM_PROJECT_NAME).Result; // --------------------------------------------------------------------------------------------------------------------------- // Using the regular client api, add results to the test run to complete it: TfsTeamProjectCollection tfsCollection = new TfsTeamProjectCollection(new Uri(TFS_COLLECTION_NAME), new VssCredentials()); ITestManagementService testManagement = tfsCollection.GetService<ITestManagementService>(); IEnumerable<ITestRun> testRuns = testManagement.QueryTestRuns( "SELECT * FROM TestRun WHERE TestRunID='" + testRunExtended.Id + "'"); ITestRun testRun = testRuns.First(); // Update the outcome of the test ITestCaseResultCollection results = testRun.QueryResults(); foreach (ITestCaseResult result in results) { result.Outcome = testResult == "Pass" ? Microsoft.TeamFoundation.TestManagement.Client.TestOutcome.Passed : Microsoft.TeamFoundation.TestManagement.Client.TestOutcome.Failed; result.State = TestResultState.Completed; result.Save(); } testRun.Save(); testRun.Refresh(); } 组件。

我遇到的问题是<Picker />是一个字符串,但是我希望它返回一个数字。我已经看到了解析它的方法,但是我不确定如何在本机中执行此操作。

value='1'

谢谢。

3 个答案:

答案 0 :(得分:1)

您可以使用parseInt函数或Number构造函数将字符串解析为数字。

this.setState({myNumber: parseInt(itemValue, 10)})

答案 1 :(得分:1)

对我来说,更好的方法-use unary "+"

this.setState({myNumber: +itemValue})

答案 2 :(得分:0)

尝试使用以下内容:

onValueChange={(itemValue) => this.setState((itemValue)=>{myNumber: Number(itemValue)})}>