使用 Chained Jquery 插件
Using Chained Jquery plugin
我正在尝试在 CakePhp 中使用远程 Chained 插件 (http://www.appelsiini.net/projects/chained)
我使用 Jquery 来测试一个警报,它可以工作,但只是链接的插件不工作。我正在尝试使用他们的代码来遵循他们网站上的示例。如果您想查看我的页面,请转到 http://team.southpacificavionics.com/customers/test
登录:访客
密码:密码
jquery.chained.remote.min.js
/*! Chained 1.0.0 - MIT license - Copyright 2010-2014 Mika Tuupola */
!function(a){"use strict";a.fn.remoteChained=function(b){var c=a.extend({},a.fn.remoteChained.defaults,b);return c.loading&&(c.clear=!0),this.each(function(){function b(b){var c=a(":selected",d).val();a("option",d).remove();var e=[];if(a.isArray(b))e=a.isArray(b[0])?b:a.map(b,function(b){return a.map(b,function(a,b){return[[b,a]]})});else for(var f in b)b.hasOwnProperty(f)&&e.push([f,b[f]]);for(var g=0;g!==e.length;g++){var h=e[g][0],i=e[g][1];if("selected"!==h){var j=a("<option />").val(h).append(i);a(d).append(j)}else c=i}a(d).children().each(function(){a(this).val()===c+""&&a(this).attr("selected","selected")}),1===a("option",d).size()&&""===a(d).val()?a(d).prop("disabled",!0):a(d).prop("disabled",!1)}var d=this,e=!1;a(c.parents).each(function(){a(this).bind("change",function(){var f={};a(c.parents).each(function(){var b=a(this).attr(c.attribute),e=(a(this).is("select")?a(":selected",this):a(this)).val();f[b]=e,c.depends&&a(c.depends).each(function(){if(d!==this){var b=a(this).attr(c.attribute),e=a(this).val();f[b]=e}})}),e&&a.isFunction(e.abort)&&(e.abort(),e=!1),c.clear&&(c.loading?b.call(d,{"":c.loading}):a("option",d).remove(),a(d).trigger("change")),e=a.getJSON(c.url,f,function(c){b.call(d,c),a(d).trigger("change")})}),c.bootstrap&&(b.call(d,c.bootstrap),c.bootstrap=null)})})},a.fn.remoteChainedTo=a.fn.remoteChained,a.fn.remoteChained.defaults={attribute:"name",depends:null,bootstrap:null,loading:null,clear:!1}}(window.jQuery||window.Zepto,window,document);
test.ctp
<?php echo $this->Html->script('jquery.min'); ?>
<?php echo $this->Html->script('jquery.chained.remote.min'); ?>
<script type="text/javascript">
$(document).ready(function () {
alert('java is working');
});
</script>
<select id="mark" name="mark">
<option value="">--</option>
<option value="bmw">BMW</option>
<option value="audi">Audi</option>
</select>
<select id="series" name="series">
<option value="">--</option>
<option value="series-3" class="bmw">3 series</option>
<option value="series-5" class="bmw">5 series</option>
<option value="series-6" class="bmw">6 series</option>
<option value="a3" class="audi">A3</option>
<option value="a4" class="audi">A4</option>
<option value="a5" class="audi">A5</option>
</select>
<script>
(function() {
$("#series").chainedTo("#mark");
});
</script>
这实际上与 CakePHP 无关 - 它是一个客户端 javascript 库。
但是你有两个问题,第一:
(function() {
$("#series").chainedTo("#mark");
});
实际上不是 "running",您只是定义了一个匿名函数,如果被调用,会 运行。它可能应该被移动到您 alert
所在的位置:
<script type="text/javascript">
$(document).ready(function () {
$("#series").chainedTo("#mark");
});
</script>
现在会 运行,但是如果您检查浏览器控制台,它会出错,类似于:
Uncaught TypeError: $(...).chainedTo is not a function
看起来库没有 运行 正确。
我不确定您从哪里获得 jquery 链接库的源代码,但它不是您 link 的 github 获取的页面中的当前版本来自:
此处列出直接最小化版本:
https://raw.githubusercontent.com/tuupola/jquery_chained/master/jquery.chained.min.js
我正在尝试在 CakePhp 中使用远程 Chained 插件 (http://www.appelsiini.net/projects/chained) 我使用 Jquery 来测试一个警报,它可以工作,但只是链接的插件不工作。我正在尝试使用他们的代码来遵循他们网站上的示例。如果您想查看我的页面,请转到 http://team.southpacificavionics.com/customers/test 登录:访客 密码:密码
jquery.chained.remote.min.js
/*! Chained 1.0.0 - MIT license - Copyright 2010-2014 Mika Tuupola */
!function(a){"use strict";a.fn.remoteChained=function(b){var c=a.extend({},a.fn.remoteChained.defaults,b);return c.loading&&(c.clear=!0),this.each(function(){function b(b){var c=a(":selected",d).val();a("option",d).remove();var e=[];if(a.isArray(b))e=a.isArray(b[0])?b:a.map(b,function(b){return a.map(b,function(a,b){return[[b,a]]})});else for(var f in b)b.hasOwnProperty(f)&&e.push([f,b[f]]);for(var g=0;g!==e.length;g++){var h=e[g][0],i=e[g][1];if("selected"!==h){var j=a("<option />").val(h).append(i);a(d).append(j)}else c=i}a(d).children().each(function(){a(this).val()===c+""&&a(this).attr("selected","selected")}),1===a("option",d).size()&&""===a(d).val()?a(d).prop("disabled",!0):a(d).prop("disabled",!1)}var d=this,e=!1;a(c.parents).each(function(){a(this).bind("change",function(){var f={};a(c.parents).each(function(){var b=a(this).attr(c.attribute),e=(a(this).is("select")?a(":selected",this):a(this)).val();f[b]=e,c.depends&&a(c.depends).each(function(){if(d!==this){var b=a(this).attr(c.attribute),e=a(this).val();f[b]=e}})}),e&&a.isFunction(e.abort)&&(e.abort(),e=!1),c.clear&&(c.loading?b.call(d,{"":c.loading}):a("option",d).remove(),a(d).trigger("change")),e=a.getJSON(c.url,f,function(c){b.call(d,c),a(d).trigger("change")})}),c.bootstrap&&(b.call(d,c.bootstrap),c.bootstrap=null)})})},a.fn.remoteChainedTo=a.fn.remoteChained,a.fn.remoteChained.defaults={attribute:"name",depends:null,bootstrap:null,loading:null,clear:!1}}(window.jQuery||window.Zepto,window,document);
test.ctp
<?php echo $this->Html->script('jquery.min'); ?>
<?php echo $this->Html->script('jquery.chained.remote.min'); ?>
<script type="text/javascript">
$(document).ready(function () {
alert('java is working');
});
</script>
<select id="mark" name="mark">
<option value="">--</option>
<option value="bmw">BMW</option>
<option value="audi">Audi</option>
</select>
<select id="series" name="series">
<option value="">--</option>
<option value="series-3" class="bmw">3 series</option>
<option value="series-5" class="bmw">5 series</option>
<option value="series-6" class="bmw">6 series</option>
<option value="a3" class="audi">A3</option>
<option value="a4" class="audi">A4</option>
<option value="a5" class="audi">A5</option>
</select>
<script>
(function() {
$("#series").chainedTo("#mark");
});
</script>
这实际上与 CakePHP 无关 - 它是一个客户端 javascript 库。
但是你有两个问题,第一:
(function() {
$("#series").chainedTo("#mark");
});
实际上不是 "running",您只是定义了一个匿名函数,如果被调用,会 运行。它可能应该被移动到您 alert
所在的位置:
<script type="text/javascript">
$(document).ready(function () {
$("#series").chainedTo("#mark");
});
</script>
现在会 运行,但是如果您检查浏览器控制台,它会出错,类似于:
Uncaught TypeError: $(...).chainedTo is not a function
看起来库没有 运行 正确。
我不确定您从哪里获得 jquery 链接库的源代码,但它不是您 link 的 github 获取的页面中的当前版本来自:
此处列出直接最小化版本:
https://raw.githubusercontent.com/tuupola/jquery_chained/master/jquery.chained.min.js