开发者

Passing jQuery object property to function

开发者 https://www.devze.com 2023-02-26 18:30 出处:网络
new $.Feed({ container: \"#us-feed\", feedUrl: \"http://www.somefeed.com/feed/\", onFeedLoad: function(feedResult) {
    new $.Feed({
        container: "#us-feed",
        feedUrl: "http://www.somefeed.com/feed/",
        onFeedLoad: function(feedResult) {
            formatFeed(feedResult);
        }
    开发者_如何学Python});

Pretty basic syntax question: what is the syntax to pass the container property to the formatFeed function for use as a variable?


You can reference the current object with this:

new $.Feed({
    container: "#us-feed",
    feedUrl: "http://www.somefeed.com/feed/",
    onFeedLoad: function(feedResult) {
        formatFeed(feedResult, this.container);
    }
});

As mentioned in the comments, that depends a lot on where and how onFeedLoad is being called. If you want a safe solution just store the container text in a temporary variable as mcos already suggested:

var container = "#us-feed";
new $.Feed({
    container: container,
    feedUrl: "http://www.somefeed.com/feed/",
    onFeedLoad: function(feedResult) {
        formatFeed(feedResult, container);
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消