0

tumblr ブログから RSS フィードを解析しようとしています。これは、RSS フィードからの xml のスニペットです。

<item>
    <title>title goes here</title>
    <description>
        <img src="http://media.tumblr.com/ajfafh.jpg"/>
        <p>text description goes here</p>
    </description>
    .
    .
</item>

このコードを試して、説明タグ内の img タグを取得します

function parse(xml){
    xml.find('item').each(function(index){
        var $item = $(this);
        var df = $item.find('description')[0].textContent;
        var $asdf = $(df).find('img').first()[0];

        var item = {
            index: index,
            description: $item.find('description')[0].textContent,
            img: $asdf
        }

        console.log(item.img);// return exactly the img tag just like what i want <img>
        // i also try this one
        console.log($(item.description).find('img').first());// return [<img src />]

        this.container.append(Mustache.to_html(this.template, item));
        //this.container = $('#container')
        //this.template = $('#template')
    });
}

私は mustache.js を使用してそれを html にロードします。HTML

<ul id="container">
    <script id="template" type="text/template">
    <li>{{img}}</li>
    </script>
</ul>

しかし、ブラウザで実行すると、[object HTMLImageElement] が返されますが、console.log() は正しい値を返します。なぜそれが起こるのですか?私は何を取りこぼしたか?

4

1 に答える 1

0

さて、あなたはlogitem.img を ing していますが、追加しようとしていますitemitem.img代わりに追加したいと思います。

于 2012-05-22T14:07:25.957 に答える