选择带子项的对象时过滤元素()

时间:2016-07-03 16:13:04

标签: angularjs

在这个PLUNK中我有一个指令,它向元素追加一个有三个孩子的div。两个孩子是div,第三个孩子是跨度。

我需要循环遍历孩子,但丢弃任何不是div的东西。

我试过

var children = wrap.children();

但它不会返回任何内容。这可以工作,但也会缩短范围

    directive.link = function (scope, element, attrs) {

       var wrap = angular.element('<div id="wrap"></div>');
       var wrapc = $compile(wrap)(scope)
       element.append(wrapc); 

       var node1 = angular.element('<div id="node1"></div>');
       var node1c = $compile(node1)(scope)
       wrapc.append(node1c);

       var node2 = angular.element('<div id="node2"></div>');
       var node2c = $compile(node2)(scope)
       wrapc.append(node2c);

       var span1 = angular.element('<span id="span1">text</span>');
       var span1c = $compile(span1)(scope)
       wrapc.append(span1c);

        // var children = wrap.children().find( "div" );
        var children = wrap.children();
        angular.forEach(children, function(value, key){
            console.log(value);
        });
    };

如何使这项工作?

的Javascript

<?php 
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 1);
set_time_limit(0);

$apiKey = 'my key';
$apiSecret = 'my secret';
require_once 'Dailymotion.php';
// Instanciate the PHP SDK.
$api = new Dailymotion();

// Tell the SDK what kind of authentication you'd like to use.
// Because the SDK works with lazy authentication, no request is performed at this point.
$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret);

// $api = new Dailymotion();
try
{
$result = $api->get(
'/video/my id',
array('fields' => array('id', 'title', 'owner'))
);

}
catch (DailymotionAuthRequiredException $e)
{
echo $e->getMessage();
// If the SDK doesn't have any access token stored in memory, it tries to
// redirect the user to the Dailymotion authorization page for authentication.
return header('Location: ' . $api->getAuthorizationUrl());
}
catch (DailymotionAuthRefusedException $e)
{
echo $e->getMessage();
// Handle the situation when the user refused to authorize and came back here.
// <YOUR CODE>
}

trace($result);

function trace($d) {
echo '<pre>';
var_dump($d);
echo '</pre>';

echo '<iframe frameborder="0" width="480" height="270" src="http://www.dailymotion.com/embed/video/my id"></iframe>';
}
?>

0 个答案:

没有答案