首页 \ 问答 \ 从Controller中使用EmberJS transitionToRoute时,如何更正URL路径中的[object%20Object]?(How do I correct [object%20Object] in URL path when using EmberJS transitionToRoute from Controller?)

从Controller中使用EmberJS transitionToRoute时,如何更正URL路径中的[object%20Object]?(How do I correct [object%20Object] in URL path when using EmberJS transitionToRoute from Controller?)

我正在尝试在模板中设置一个动作,根据动态生成的导航栏将用户转换到另一个路径,使用客户端执行的json /和js的组合。 我已经设法配置我的应用程序,以便我可以生成有效的常规路径,但我想使用转换来避免额外的页面加载。

对(希望)必要信息的要点是:

https://gist.github.com/rjfranco/5289201

JS:

App.Router.map ->
  @route 'index', {path: "/#{short_name}"}
  @route 'customList', {path: "/#{short_name}/custom-list/:list_name"}
  @route 'multiLevelList', {path: "/#{short_name}/multi-level-list/:list_name/:list_level"}

App.EventController = Em.ObjectController.extend
  goTo: (navbar_icon) ->
    @transitionToRoute navbar_icon.route, navbar_icon.context

# Sample passed navbar_icon
navbar_icon =
  img_src: '/somesource_or_another.jpg'
  display_name: 'My Link Name!'
  route: 'customList'
  context: {list_name: 'Exhibitors'}

模板:

{{#each controller.navbarIcons}}
  <li><a {{action goTo this}}><img {{bindAttr src="image_src"}} width="36" height="36" />{{display_name}}</a></li>
{{/each}}

预期页面实际上加载正常,但应用程序转换到的URL不正确,刷新会破坏应用程序。

我期待一个URL: /ruhaha/custom-list/Exhibitors
我最终得到一个像: /ruhaha/custom-list/[object%20Object]

稍微更新:我发现我可以在应用程序上滥用几种方法来产生我想要的结果:

App.handleURL('/ ruhaha /定制列表/展商)
App.Router.router.replaceURL('/ ruhaha /定制列表/展商)

这实际上会触发路由,并且在没有页面请求的情况下替换有效地将我的应用程序转换到我想要的状态的URL。 虽然这有效但我很确定这是解决这个问题的错误方法。


I'm attempting to setup an action in a template to transition users to another route based on a dynamically generated navbar, using a combination of json / and js that is executed client side. I've managed to configure my application so that I can generate regular paths that work, but I would like to use transitions to avoid additional page loads.

A gist with what is (hopefully) the necessary information is:

https://gist.github.com/rjfranco/5289201

JS:

App.Router.map ->
  @route 'index', {path: "/#{short_name}"}
  @route 'customList', {path: "/#{short_name}/custom-list/:list_name"}
  @route 'multiLevelList', {path: "/#{short_name}/multi-level-list/:list_name/:list_level"}

App.EventController = Em.ObjectController.extend
  goTo: (navbar_icon) ->
    @transitionToRoute navbar_icon.route, navbar_icon.context

# Sample passed navbar_icon
navbar_icon =
  img_src: '/somesource_or_another.jpg'
  display_name: 'My Link Name!'
  route: 'customList'
  context: {list_name: 'Exhibitors'}

template:

{{#each controller.navbarIcons}}
  <li><a {{action goTo this}}><img {{bindAttr src="image_src"}} width="36" height="36" />{{display_name}}</a></li>
{{/each}}

The expected page actually loads fine, but the url the application transitions to is not correct, and refreshing breaks the application.

I'm expecting a URL along the lines of: /ruhaha/custom-list/Exhibitors
and I end up with one like: /ruhaha/custom-list/[object%20Object]

Slight update: I've found that I could abuse a couple of methods on the app to produce the results I want:

App.handleURL('/ruhaha/custom-list/Exhibitors')
App.Router.router.replaceURL('/ruhaha/custom-list/Exhibitors')

This will actually trigger the route, and replace the url effectively transitioning my application to the state I want without a page request. Although this works I'm pretty certain this is the wrong way to take care of this issue.


原文:https://stackoverflow.com/questions/15768218
更新时间:2022-09-05 21:09

最满意答案

如果我是你,我find_all()类名作为参数传递给find()函数而不是find_all() ,我首先要查找包含你正在寻找的锚的<li>元素。 它看起来像这样

from bs4 import BeautifulSoup
import requests
username='justinbieber'
url = 'https://www.twitter.com/'+username
r = requests.get(url)
soup = BeautifulSoup(r.content)

f = soup.find('li', class_="ProfileNav-item--followers")
title = f.find('a')['title']
print title
# 81,346,708 Followers

num_followers = int(title.split(' ')[0].replace(',',''))
print num_followers
# 81346708

PS findAll() find_all()在bs4中被重命名为find_all()


If I were you, I'd be passing the class name as an argument to the find() function instead of find_all() and I'd first look for the <li> element that contains the anchor you're loooking for. It'd look something like this

from bs4 import BeautifulSoup
import requests
username='justinbieber'
url = 'https://www.twitter.com/'+username
r = requests.get(url)
soup = BeautifulSoup(r.content)

f = soup.find('li', class_="ProfileNav-item--followers")
title = f.find('a')['title']
print title
# 81,346,708 Followers

num_followers = int(title.split(' ')[0].replace(',',''))
print num_followers
# 81346708

PS findAll() was renamed to find_all() in bs4

相关问答

更多
  • 正如您现在必须学习的那样,速率限制和计数限制会阻止Twitter API上的大量操作。 有了这些限制,大多数答案都不够充分,但这是我将使用的一般方法: 使用“ 列表关注者”查询获取所有关注者ID的列表 。 确保最大数量为5000,以减少查询次数。 如果您的用户拥有数十万(甚至数百万)的关注者,这不是最佳选择,但仍然是最有效的选择。 使用该列表,您可以执行查询用户详细信息查询。 此处的情况更糟糕,因为逗号分隔的用户ID的最大数量为100.您可以考虑跟踪UserID以按上次扫描的活动/日期对其进行分类,以避免重 ...
  • 在版本1.1中,您必须创建一个Twitter应用程序,然后使用oauth_token,oauth_token_secret,oauth_consumer_key,oauth_consumer_secret值来调用REST API。 请参阅以下文章。 他们用代码解释如何连接到Twitter并获取所需的详细信息。 http://aspxdeveloper.blogspot.com.au/2013/06/twitter-api-11-example-on-c-asp-dot-net.html https://um ...
  • 这是一个奇怪的。 我写了代码,应该拉数字,但它也一直返回null 。 我终于弄清楚当我拉出元素然后写出outerHTML时发生了什么。 页面加载期间正在更改元素。 WebDriver driver = new FirefoxDriver(); driver.get("https://twitter.com/blakeshelton"); WebDriverWait wait = new WebDriverWait(driver, 5); WebElement e = wait.until(ExpectedC ...
  • 您无需获取所有用户关注者以便对其进行计数。 使用followers_count属性。 例如: import tweepy auth = tweepy.OAuthHandler(..., ...) auth.set_access_token(..., ...) api = tweepy.API(auth) for user in tweepy.Cursor(api.followers, screen_name="twitter").items(): print user.screen_name, ...
  • $.ajax({ url: 'http://api.twitter.com/1/users/show.json', data: {screen_name: ''}, dataType: 'jsonp', success: function(data) { $('#twitter ...
  • 要使用屏幕名称检索给定用户的关注者,请参阅Twitter#getFollowersList() ,例如: long cursor = -1; PagableResponseList followers; do { followers = twitter.getFollowersList("screenName", cursor); for (User follower : followers) { // TODO: Collect top 10 follower ...
  • 这段代码对我来说很好: #!/usr/bin/env python import requests from json import loads username = "liamgiannini" r = requests.get('https://www.instagram.com/'+username) html = r.text.encode("utf-8") text = html[html.index("window._sharedData = ")+21:] text = (text[:t ...
  • 相关文章

    更多
  • Object Oriented Programming
  • spring3 @controller注解 没有用
  • 第四章 Controller接口控制器详解(1)——跟着开涛学SpringMVC
  • spring mvc 页面传值到controller
  • 第四章 Controller接口控制器详解(3)——跟着开涛学SpringMVC
  • 第四章 Controller接口控制器详解(5)——跟着开涛学SpringMVC
  • 第四章 Controller接口控制器详解(6)——跟着开涛学SpringMVC
  • 在Controller中调用YMP-WeChat模块微信API方法代码实例
  • 第四章 Controller接口控制器详解(2)——跟着开涛学SpringMVC
  • JS URL编码函数
  • 最新问答

    更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。