【问题标题】:I'm trying to find a way to embed a twitter timeline in my NativeScript app. WebView/HTMLView?我正在尝试找到一种在我的 NativeScript 应用程序中嵌入 twitter 时间线的方法。 Web 视图/HTML 视图?
【发布时间】:2019-06-21 04:24:51
【问题描述】:

我正在尝试包含我的 NativeScript 应用程序的一部分,其中包括(希望)实时 Twitter 时间线。我无法显示任何推文。

我正在使用 NativeScripts 'webview' 来引入一些 HTML。 Twitter 使用标签嵌入他们的时间线。我要展示一些东西,但没有推文。

-JS-

const Observable = require("tns-core-modules/data/observable").Observable;
const webViewModule = require("tns-core-modules/ui/web-view");

function onNavigatingTo(args) {
    const page = args.object;
    const vm = new Observable();
    // loading the WebView source while providing a HTML code
    vm.set("firstWebViewSRC", "<!DOCTYPE html><html><head><title>MyTitle</title><meta charset='utf-8' /></head><body><a class='twitter-timeline' href='https://twitter.com/RideUTA?ref_src=twsrc%5Etfw'>Tweets by RideUTA</a> <script async src='https://platform.twitter.com/widgets.js' charset='utf-8'></script></body></html>");
    vm.set("resultFirstWebView", "");
    // loading the WebView source from a local file
    vm.set("resultSecondWebView", "");
    page.bindingContext = vm;
}

-XML-

<GridLayout rows="100 50 * 50" columns="*">
    <WebView row="0" col="0" loaded="onFirstWebViewLoaded" src="{{ firstWebViewSRC }}"/>
    <Label row="1" text="{{ resultFirstWebView }}" textWrap="true" />

</GridLayout>

我想要一个 Twitter 个人资料的最新时间表。我得到了一些结果,但没有推文。

【问题讨论】:

  • 您可以直接在Webview中加载本地HTML,如果您喜欢加载一次并在Label中显示结果,我建议使用HTMLString

标签: javascript xml twitter sass nativescript


【解决方案1】:

我创建了一个游乐场here。时间轴在这里加载得很好。我在真实的ios设备上测试过。

<WebView height="1200px" src="{{firstWebViewSRC}}" />

firstWebViewSRC:"<html><head><title>MyTitle</title><meta charset='utf-8' /></head><body><a class='twitter-timeline' href='https://twitter.com/RideUTA?ref_src=twsrc%5Etfw'>Tweets by RideUTA</a> <script async src='https://platform.twitter.com/widgets.js' charset='utf-8'></script></body></html>"

附:我不得不从您的代码中删除 DOCTYPE

【讨论】:

  • 代码在 main-page.js 还是 main-view-model.js 有关系吗?
  • 应该没关系,只要你能够绑定值
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-19
  • 1970-01-01
  • 1970-01-01
  • 2021-08-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多