【发布时间】:2014-05-21 16:39:51
【问题描述】:
function OutletsView(){
self = this;
self.locations = ko.observableArray(<?php echo json_encode($locations); ?>);
}
ko.applyBindings(new OutletsView());
位置来自结构
[
{
name: 'Demo',
oid: 1,
children: [
{
id: 2,
name: 'de'
},
{
id: 2,
name: 'de'
}
]
},
{
name: 'Demo',
oid: 1,
children: [
{
id: 2,
name: 'de'
},
{
id: 2,
name: 'de'
}
]
}
]
我需要绑定 oid 并在 html 中进行更改
<script type="text/html" id="location-filter">
<div>
<div data-bind="text: oid"></div>
<div>
<ul data-bind="foreach: locations">
<li data-bind="text: name, click: $parent.applyFilter(id, name, $parent)"></li>
</ul>
</div>
</div>
</script>
所以我想改变 oid 但找不到怎么做 谁能帮帮我?
编辑:
function OutletsView(){
self.locations = ko.observableArray([]);
self.getChildLocations = function(id){
$.post('<?=$this->url(array('controller' => 'location', 'action' => 'get-locations'), 'default', true); ?>',
{id: id},
function(data){
var parsed = $.parseJSON(data);
var item = new Location(parsed);
self.locations.push(item);
}
);
}
}
function locationItem(el){
tself = this;
tself.id = el.id;
tself.name = el.name;
tself.lo_idx = el.lo_idx;
tself.cls = ko.observable(el.cls);
}
function Location(item){
kself = this;
kself.using_id = 0;
kself.using_name = item[0].location_type;
kself.cls = ko.observable('jcsik jactive jsminimize');
kself.locations = [
new locationItem({id: 0, name: item[0].location_type, lo_idx: 0, cls: ''}),
new locationItem({id: 1, name: 'Не выбрано', lo_idx: 0, cls: 'jexpand'})
];
$.each(item, function(i, el){
kself.locations.push(new locationItem(el));
});
kself.getLocation = function(){
return kself;
}
}
【问题讨论】: